获取width属性值

时间:2017-12-02 12:00:39   收藏:0   阅读:288

技术分享图片

<body>
    <div id="box"></div>
    <style>
        #box{
            width:200px;
            height:100px;
            padding:5px;
            border:1px solid red;
            margin:10px auto;
        }
    </style>
    
    <script>
        var oBox=document.getElementById(‘box‘);
        var cssJson=oBox.currentStyle||getComputedStyle(oBox);//兼容
        alert(cssJson.width);//width    200px
        alert(oBox.clientWidth);//width+padding    210px
        alert(oBox.offsetWidth);//width+padding+border   212px
    </script>
</body>

 

原文:http://www.cnblogs.com/yuqlblog/p/7953713.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!