【问题标题】:Microsoft JScript runtime error: Unable to get value of the property 'value': object is null or undefinedMicrosoft JScript 运行时错误:无法获取属性“值”的值:对象为空或未定义
【发布时间】:2012-04-30 07:38:36
【问题描述】:

我在做一个asp.net网页,有一个texbox,我想确保输入的文本少于3个字符,我写的代码是

<input type="text" name="searchcatid" size="15" onblur="test_length(Index.searchchatid)" />

<script>

function test_length(testcontrol) {


    var teststring = testcontrol.value;

    if (teststring.length >= 3) {
        alert("ID must be 3 or fewer characters!");
        testcontrol.focus();
    }
    else {
    }


} 


</script>

并且我收到错误“Microsoft JScript 运行时错误:无法获取属性‘值’的值:对象为空或未定义”,每当我输入某些内容时,我都不知道出了什么问题,因为我真的是新手asp.net,甚至不确定我的代码是否真的可以工作,希望有人可以帮助我,非常感谢

【问题讨论】:

    标签: javascript asp.net-mvc-3


    【解决方案1】:

    以适当的方式传递输入元素:

    <input type="text" name="searchcatid" size="15" onblur="test_length(this);" />
    

    如果你 registered your eventhandlers via JavaScript 而不是使用内联事件会更好。

    【讨论】:

      【解决方案2】:

      是不是有问题,请检查

      name="searchcatid"Index.searchchatid 拼写 searchcatid 不匹配

      【讨论】:

        猜你喜欢
        • 2013-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多