javascript 中未定义 null 或对象错误
我是 mvc 2.0,因为在特定的文本框中设置了文本框的最大字符...但似乎出现未定义的错误这是我的观点
<td>
<%= Html.TextArea("Description", Model.Description, new{id = "descriptionId",onKeyDown = "limitText(this.form.Description,this.form.countdown,1000);",onKeyUp = "limitText(this.form.Description,this.form.countdown,1000);"})%>
</td>
这是我的脚本...
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
alert(limitCount.value);
}
}
I am mvc 2.0 for that in a particular textbox have set the maximun charcter for the textbox...but seems to get undefined error this is my view
<td>
<%= Html.TextArea("Description", Model.Description, new{id = "descriptionId",onKeyDown = "limitText(this.form.Description,this.form.countdown,1000);",onKeyUp = "limitText(this.form.Description,this.form.countdown,1000);"})%>
</td>
This is my script....
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
alert(limitCount.value);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您可能将 ASP.NET 控件 ID 与 JavaScript ID 混淆了。在 HTML 源输出中查找该描述文本框的 ID 值,并在当前拥有 this.form.Description 的位置使用该值。它最终可能会是 this.form.DescriptionId 或 this.form.DescriptionId_ctl0 或 ASP.NET 决定为您生成的其他一些可笑的 ID。
Looks like you might have ASP.NET control IDs confused with JavaScript IDs. Look in the HTML source output for the ID value on that description text box and use that where you currently have this.form.Description. It will probably end up as this.form.DescriptionId or this.form.DescriptionId_ctl0 or some other ridiculous ID that ASP.NET decides to generate for you.