永发信息网

js怎样批量设置元素的style属性值

答案:2  悬赏:0  手机版
解决时间 2021-11-09 17:35
  • 提问者网友:萌卜娃娃
  • 2021-11-08 19:46
js怎样批量设置元素的style属性值
最佳答案
  • 五星知识达人网友:荒野風
  • 2021-11-08 20:59
firefox等可以使用:
document.getElementById("id").setAttribute("style","top:20px;left:20px;color:red;");IE中则必须使用style.cssText
document.getElementById("id").style.cssText = "top:20px;left:20px;color:red;";
全部回答
  • 1楼网友:逐風
  • 2021-11-08 22:36
var style=
{
    color:"#fcc",
    position:"absolute"
}
for( var i in style)
{
   document.getElementById("id").style[i]=style[i] 
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯