js setAttribute() 兼容方法

1 var sub = document.getElementById("sub");
2     sub.setAttribute("disabled", "disabled");    // 兼容的
3     sub.setAttribute("style", "position:absolute;left:100px;top:100px;");    // IE 7 不能设置成功
4 
5     // 以下为兼容方法: 
6     var cssText = "position:absolute;left:100px;top:100px;";
7     sub.style.cssText = cssText;    // IE 7
8     sub.setAttribute("style", cssText);    // 非 IE7

 

posted @ 2013-09-27 10:55  楚玉  阅读(318)  评论(0编辑  收藏  举报