我不使用框架,我默认使用 JavaScript。
我需要知道输入文本元素的宽度,在我使用的优秀浏览器中:
width = document.defaultView.getComputedStyle(el, "").getPropertyValue('width');
但是在他妈的 Internet Explorer 中使用:
if (typeof el.currentStyle['width'] == "undefined" || el.currentStyle['width'] == 'NaN') {
width = el.currentStyle['width'];
} else {
width = null;
}
如果宽度由 css 或样式属性设置,则此方法有效,但如果大小是默认值(由大小属性设置或未设置)el.currentStyle['width'] 是未定义。
我需要知道没有设置属性的元素的宽度。
最佳答案
var elwidth= el.offsetWidth+'px';
关于javascript - 如何在 IE 中获取输入元素的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7589660/