-
var width = null;
-
var height = null;
-
// 对于单个数据而言只有0 NaN null undefined "" 是假的其它的都是真的 if(div.currentStyle){ //IE下
-
width = div.currentStyle.width;
-
height = div.currentStyle.height;
-
}else{ //IE以外其它的浏览器
-
width = getComputedStyle(div).width;
-
height = getComputedStyle(div).height;
-
}
-
console.log(width,height);
IE浏览器兼容处理
本文介绍了一种在不同浏览器中获取HTML元素宽度和高度的方法。针对IE浏览器和其他现代浏览器提供了兼容的解决方案,通过JavaScript代码实现对元素当前样式属性的读取,并记录了获取到的宽度和高度值。

被折叠的 条评论
为什么被折叠?



