获取元素计算后的css样式封装:

    function getCss(obj,attribute) {
        if(obj.currentStyle) {
            return obj.currentStyle[attribute];}else {
        return window.getComputedStyle(obj,null)[attribute];}
    }

案例:

<!DOCTYLE html>
<html>
<head>
    <meta charset="uft-8" />
    <style>
        #box {width:100px; height: 100px; background:#dfd; position:absolute; left:100px; top:100px;}
    </style>
</head>
<body>
<button >200</button>
<button >600</button>
<div ></div>
</body>
</html>
<script>
    function getCss(obj,attribute) {
        if(obj.currentStyle) {
            return obj.currentStyle[attribute];}else {
        return window.getComputedStyle(obj,null)[attribute];}
    }
    console.log(getCss(box,'zIndex'));
</script>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-04-05
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案