批量修改样式目的是尽量避免页面reflow,提高性能。
firefox等可以使用
IE中则必须使用style.cssText
参考:[url]http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html[/url]
补充一下,目前style.cssText类似innerHTML了,已经成为一个web开发的事实标准。因此测试显示firefox浏览器也支持这种方式。
firefox等可以使用
dom.setAttribute("style","width:10px;height:10px;border:solid 1px red;")
IE中则必须使用style.cssText
dom1.style.cssText = "width:10px;height:10px;border:solid 1px red;";
参考:[url]http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html[/url]
补充一下,目前style.cssText类似innerHTML了,已经成为一个web开发的事实标准。因此测试显示firefox浏览器也支持这种方式。