js访问修改css属性不能兼容chrome IE下是这个:document.styleSheets[i].rulesFF:document.styleSheets[i].cssRuleschrome? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.quirksmode.org/dom/changess.html和IE一样。。你自己试试 一试 二查文档 三谷歌 四csdn 无发帖 江湖规矩我不懂吗 没办法了 http://stackoverflow.com/你去这上面提试试。。看看外国人有什么看法 用js修改css,你不觉得是件十分危险的事情吗? <!DOCTYPE HTML><html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <div class="a">111111111</div> <div class="b">111111111</div> <div class="c">111111111</div> <script> function $(el){ return typeof el == 'string' ? document.getElementById(el) : el; } ;(function(w, d){ var ie = !+[1,]; var o = null; var styleSheet = function(){ this.init(); }; styleSheet.prototype = { init: function(){ var h = d.getElementsByTagName('head')[0]; var s = d.createElement('style'); h.appendChild(s); o = d.styleSheets[d.styleSheets.length-1]; }, add: function(selector, style){ ie ? o.addRule(selector, style) : o.insertRule(selector + "{" + style + "}", o.cssRules.length); }, del: function(index){ ie ? o.removeRule(index) : o.deleteRule(index); }, getRules: function(){ return ie ? o.rules : o.cssRules; }, getRule: function(selector){ var rules = this.getRules(); for(var i = 0, len = rules.length; i < len; i++){ var r = rules[i]; if( r.selectorText == selector ){ return r; } } return null; } } w.styleSheet = styleSheet; })(window, document); var s = new styleSheet; s.add('.a', 'color:red;') s.add('.a', 'font-size:111px;') s.add('.a', 'font-size:11px;') s.add('.b', 'color:blue;') s.del(2) // 删除 font-size:11px; alert( s.getRule('.a').style['color'] ) </script> </body></html>参考下。 字符串问题 JS滚动特效让IE死了。 关于一段js代码的理解问题 关于框架的问题 如何按中键不出现那个上下的轱辘? 正则表达式求助 完全按照书上例子做的,怎么还会错呢?大家帮忙看看问题出在哪儿? XMLDOMDocument.ontransformnode事件怎么不触发? 返回一个页面并刷新这个页面,该怎么办? [接]公开我今天的劳动,希望对大家有用。。 http://lostinet.d2g.com/temp/public/Library/JScript.txt extjs导execl,出错,报传递给系统调用的数据区域太小,求救 用FusionCharts做类似实时监控报表的问题
和IE一样。。你自己试试
你去这上面提试试。。看看外国人有什么看法
<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
</head>
<body>
<div class="a">111111111</div>
<div class="b">111111111</div>
<div class="c">111111111</div>
<script>
function $(el){
return typeof el == 'string' ? document.getElementById(el) : el;
}
;(function(w, d){
var ie = !+[1,];
var o = null;
var styleSheet = function(){
this.init();
};
styleSheet.prototype = {
init: function(){
var h = d.getElementsByTagName('head')[0];
var s = d.createElement('style');
h.appendChild(s);
o = d.styleSheets[d.styleSheets.length-1];
},
add: function(selector, style){
ie ?
o.addRule(selector, style)
:
o.insertRule(selector + "{" + style + "}", o.cssRules.length);
},
del: function(index){
ie ?
o.removeRule(index)
:
o.deleteRule(index);
},
getRules: function(){
return ie ?
o.rules
:
o.cssRules;
},
getRule: function(selector){
var rules = this.getRules();
for(var i = 0, len = rules.length; i < len; i++){
var r = rules[i];
if( r.selectorText == selector ){
return r;
}
}
return null;
}
}
w.styleSheet = styleSheet;
})(window, document);
var s = new styleSheet;
s.add('.a', 'color:red;')
s.add('.a', 'font-size:111px;')
s.add('.a', 'font-size:11px;')
s.add('.b', 'color:blue;')
s.del(2) // 删除 font-size:11px;
alert( s.getRule('.a').style['color'] )
</script>
</body>
</html>
参考下。