javascript获取div的width、height

dcument.getElementById(‘element').style.xxx

可以获取元素的样式信息,但是它获取的只是DOM元素style属性里的样式规则,对于通过class属性引用的外部样式表,获取不到

IE和其他浏览器不一样


 
var oBox = document.getElementById("box");
var width =  oBox.currentStyle.width ;

 其他浏览器
 var width = getComputedStyle(oBox,false).width;

兼容写法

var width = oBox.currentStyle? oBox.currentStyle.width :getComputedStyle(oBox,false).width;
var height = oBox.currentStyle? oBox.currentStyle.height :getComputedStyle(oBox,false).height;



你可能感兴趣的:(javascript获取div的width、height)