<DIV style="position:absolute;top:50px;left:100px;"></DIV>
上面的50px我要有一個已經存在並賦值的JS變量start代替,應該怎么寫?
js在方法中寫:
var div=document.getElementById("這個DIV的ID");//得到這個DIV。
div.style.top=start+'px'
在vue的style中使用變量
<span :style="{'color': color}"></span>
此處的color可以是你穿進去的變量,也可以是后台返回的數據
或者
var color = newvalue;
data() {
return {
changeStyle:'background:'+color
}
}
html中直接這樣就可以了
<span style="margin-top:5px;" :style="changeStyle"></span>
