![](/img/trans.png)
[英](IE Specific) How to determine if entered text is longer then input element's width
[英]How get the width of an input element in IE?
我不使用框架,默認情況下使用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';
只需使用Jquery。 它具有.width和.height函數,它們也可以在ie6中工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.