addRule在firefox下的兼容写法

2019-06-03 15:23:18王振洲

  input{}{background-color:gray}
  button{}{margin-top:70px;width:50px}
</style>

<!--  by Go_Rush(阿舜) from http://ashun.cnblogs.com/ --->

<div id="a1">
divdiv
  <span>
    spanspan
    <h2>ttttt</h2>
</span>
    <input>
</div>
<script>
function f(){
  var rule="#a1 *{background-color:red}";
  var index=document.styleSheets[0].cssRules.length;
  document.styleSheets[0].insertRule(rule, index);
}
</script>

<button onclick=f()>转</button>