2019-04-11函数返回值的使用,获取元素样式getComp

2019-04-17  本文已影响0人  果冻_4c9b
   <!DOCTYPE html>
     <html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <script type="text/javascript">
        function tab(){
    return function(){
        return 1;
    }                           
        }
        var num = tab();
        console.log(num());     
    </script>
</body>
 </html>

获取元素样式

<!DOCTYPE html>
  <html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">
        #box {

            width: 100px;
            height: 100px;
            border: #000000 1px solid;
        }
    </style>
</head>
<body>
    <div id="box">  </div>
    <script type="text/javascript">
        var oBox = document.getElementById('box');
        // if(){} 颜色和路径不可以作为条               
        // 样式是可写不可读(行间样式除外)
        // console.log(oBox.style.width);
        // 获取样式函数
        //          console.log(getComputedStyle(oBox)['width']);
        //              console.log(getComputedStyle(oBox).width);              
        function getStyle(obj, attr) {
            return getComputedStyle(obj)[attr];
        }
        console.log(getStyle(oBox, 'width'));
    </script>
</body>
 </html>
上一篇下一篇

猜你喜欢

热点阅读