开发者

How get the width of an input element in IE?

开发者 https://www.devze.com 2023-04-08 22:10 出处:网络
I dont work with a framework, i\'m working with JavaScript by default. I need to know the width of an input text element, in the good browsers i use:

I dont work with a framework, i'm working with JavaScript by default.

I need to know the width of an input text element, in the good browsers i use:

width = document.defaultView.getComputedStyle(el, "").getPropertyValue('width');

But in the f**ing Internet Explorer use:

if (typeof el.currentStyle['width'] == "undefined" || el.currentStyle['width'] == 'NaN') {
  width = el.currentStyle['width'];
} else {
  width = null;
}

This works, if it is set the w开发者_开发问答idth by css or style propertie, but if the size is a default (set by size propertie or dont set) el.currentStyle['width'] is undefined.

I need to know the width of an element without propertie set.


var elwidth= el.offsetWidth+'px';


Just use Jquery. It has .width and .height functions which work in ie6 as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消