用JS打开网页时自动更改css样式,可用于处理浏览器兼容

代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script>
  window.onload=function(){(window.onresize=function(){
      var height=document.documentElement.clientHeight;
    document.getElementById('test').style.height=height+'px';
    document.getElementById('test').style.color='red';
    })()
  }
  </script>
</head>
<body>
  <div id='test' style='background:yellow'>
    测试
  </div>
</body>
</html>

效果:

原文地址:https://www.cnblogs.com/hltswd/p/5128688.html