Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 javascript 更改我的 div 的宽度值。使用:
document.getElementById("id").style.width = "25%";
适用于字符串文字,但我想使用变量设置值。
当连接字符串和变量时,javascript 将使用它们的字符串表示,请尝试以下操作:
var variable = 25; document.getElementById("id").style.width = variable + "%";