87,924
社区成员
发帖
与我相关
我的任务
分享
<STYLE>
.theforever {width:450px;color:red;}
#theforever {width:350px;color:silver;}
</STYLE>
<div class="theforever">这里应该是红色的,但它会被下面的JS通过改变CSS样式设置而改变颜色</div>
<div id="theforever">这里应该是银灰色的,的确这个不会发生变化,只作为对比</div>
<style>
.abc{
background:blue;
}
</style>
<script>
if(document.all){
document.styleSheets[0].cssText=document.styleSheets[0].cssText.replace(/red/g,"yellow");
}else{
document.styleSheets[0].cssRules[0].style["color"] = "yellow" ;
//.cssText=document.styleSheets[0].cssRules[0].cssText.replace(/red/g,"yellow");
}
</script>