【发布时间】:2015-01-09 07:44:14
【问题描述】:
我有这个控件并试图获取 offsetWidth、clientWidth 和 scrollWidth..
<span class="label-block" style="height: 19px; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;">
<label for="ctl00_Form_PlaceHolder_chkIsAnnualSelfInsuranceRenewalCertificaterequired" id="tid" style="background-color:Transparent;">
Annual Self Insurance Renewal Certificate Required
</label>
</span>
我的代码..
var a=$("#tid").offsetWidth;
var b=$("#tid").clientWidth;
var c=$("#tid").scrollWidth;
alert("offset Width =" +a);
alert("client Width =" +b);
alert("scroll Width =" +c);
警报消息显示为“未定义” 我在 Chrome 和 IE11 中都试过,结果都一样。
【问题讨论】:
-
尝试记录这些变量以确保您首先在其中包含某些内容。
-
变量是被创建的,所以之前不可能有值
-
您正在混合使用 javascript 和 jquery。例如,offsetWidth 用于 js 对象,而您正尝试在 jquery 对象上使用它
标签: javascript jquery html dom