2011-09-28 86 views
2

我不使用框架,我默認使用JavaScript。如何獲取IE中輸入元素的寬度?

我需要知道輸入的文本元素的寬度,在好的瀏覽器使用:

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或style屬性設置了寬度,但是如果大小是默認值(由size properties設置或不設置)el.currentStyle ['width']未定義。

我需要知道沒有設置屬性的元素的寬度。

+6

投了褻瀆禁止IE – frosty

+0

看到http://stackoverflow.com/questions/171542/proper-ie6-html-element-dimensions –

+0

你拼錯滾泥荷蘭國際集團 –

回答

1
var elwidth= el.offsetWidth+'px'; 
-1

只要使用Jquery。它具有在ie6中工作的.width和.height函數。