码迷,mamicode.com
首页 > 其他好文 > 详细

获取width属性值

时间:2017-12-02 12:52:58      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:var   pad   属性   nts   style   body   offset   cli   border   

技术分享图片

<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>

 

获取width属性值

标签:var   pad   属性   nts   style   body   offset   cli   border   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!