简体   繁体   English

javascript中未定义的null或对象错误

[英]Undefined null or an object error in javascript

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 我是mvc 2.0,因为在特定的文本框中已为文本框设置了maximun charcter ...但是似乎会得到未定义的错误,这是我的观点

  <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);
        }
    }

Looks like you might have ASP.NET control IDs confused with JavaScript IDs. 看起来您可能会将ASP.NET控件ID与JavaScript ID混淆了。 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. 在HTML源输出中查找该描述文本框上的ID值,并在当前具有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. 它可能最终会以this.form.DescriptionId或this.form.DescriptionId_ctl0或ASP.NET决定为您生成的其他一些可笑的ID结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM