码迷,mamicode.com
首页 > Web开发 > 详细

js获取高度和宽度

时间:2017-07-24 11:34:49      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:color   宽高   实现   tar   ntb   target   样式   bsp   idt   

CreateTime--2017年7月24日10:15:47
Author:Marydon

js获取高度和宽度

参考连接:http://www.cnblogs.com/EasonJim/p/6229517.html

实现方式:

    style.height----offsetHeight,style.width----offsetWidth

第一种情况:

  宽高都写在样式表里,就比如 #div1{width:120px;height:100px;}。

  获取id=‘div1’的宽和高,如何实现?

  通过document.getElementById(‘div1‘).style.height/width,返回值为空,即获取不到宽和高;

  必须通过document.getElementById(‘div1‘).offsetHeight/offsetWidth  

 

js获取高度和宽度

标签:color   宽高   实现   tar   ntb   target   样式   bsp   idt   

原文地址:http://www.cnblogs.com/Marydon20170307/p/7227645.html

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