日期:2014-05-16 浏览次数:20437 次
<style type="text/css" id="theme">
.skin{ width:60px;color:#ff0000; }
.skin2{ width:80px;color:#008000; }
.layout{ width:260;height:40px;color:#fff; }
</style>
<div id="test" class="skin">test skin</div>
<script type="text/javascript">
var test = document.getElementById('test');
test.className = 'skin2';
</script>
<style type="text/css" id="theme">
.skin{ width:60px;color:#ff0000; }
.skin2{ width:80px;color:#008000; }
.layout{ width:260;height:40px;color:#fff; }
</style>
<div id="test" class="skin">test skin</div>
<script type="text/javascript">
var test = document.getElementById('test');
test.style.cssText = 'width:50px;color:green';
</script>
var obj = document.styleSheets[0]; // [object StyleSheetList] 样式表的个数<link>
var rule = null; // [object CSSRule]
if (obj.cssRules){
rule = obj.cssRules[1]; // 非IE [object CSSRuleList]
} else {
rule = obj.rules[1]; // IE [object CSSRuleList]
}
console.log(rule.style.border); // 谷歌浏览器不能输出
rule.style.border = '1px solid #000'