js setattribute批量设置css样式

2019-12-25,,,

firefox等可以使用
var dom=document.getElementById("name");
dom.setAttribute("style","width:10px;height:10px;border:solid 1px red;") ;

IE中则必须使用style.cssText

var dom=document.getElementById("name");
dom1.style.cssText = "width:10px;height:10px;border:solid 1px red;";

补充一下,目前style.cssText类似innerHTML了,已经成为一个web开发的事实标准。因此测试显示firefox浏览器也支持这种方式。

您可能感兴趣的文章:

  • javascript中setAttribute()函数使用方法及兼容性
  • js中的getAttribute方法使用示例
  • javascript中attribute和property的区别详解
  • JavaScript中setAttribute用法介绍
  • JS getAttribute和setAttribute(取得和设置属性)的使用介绍
  • JavaScript中的property和attribute介绍
  • javascript setAttribute, getAttribute 在不同浏览器上的不同表现
  • Jquery attr()方法 属性赋值和属性获取详解
  • jQuery使用attr()方法同时设置多个属性值用法实例
  • jQuery使用元素属性attr赋值详解
  • JavaScript中的 attribute 和 jQuery中的 attr 方法浅析

《js setattribute批量设置css样式.doc》

下载本文的Word格式文档,以方便收藏与打印。