简体   繁体   English

在ko.observable字段上处理异常“ JavaScript运行时错误:无法获取未定义或空引用的属性'length'”?

[英]Handle exception “JavaScript runtime error: Unable to get property 'length' of undefined or null reference” on ko.observable field?

I'm using Knockoutjs on a registration form. 我在注册表上使用Knockoutjs。 I have runtime error when user click button to show password field 用户单击按钮以显示密码字段时出现运行时错误

JavaScript runtime error: Unable to get property 'length' of undefined or null reference JavaScript运行时错误:无法获取未定义或空引用的属性“ length”

how to handle runtime exception in KO.js? 如何处理KO.js中的运行时异常?

   self.showHidePasswordField = function () {

        if (self.password1().length > 0 || typeof self.password1().length !== 'undefined') {
            console.log('show');
        } else {
            console.log('hide');
        }

    };

假设您确定定义的password1可观察的,则可以尝试以下操作:

if (self.password1() != null && typeof self.password1().length !== 'undefined')

暂无
暂无

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

相关问题 JavaScript运行时错误:无法获取未定义或空引用的属性“ length” - JavaScript runtime error: Unable to get property 'length' of undefined or null reference JavaScript运行时错误:无法获取未定义或空引用的属性“ 1” - JavaScript runtime error: Unable to get property '1' of undefined or null reference JavaScript运行时错误:无法获取未定义或空引用的属性“ activate” - JavaScript runtime error: Unable to get property 'activate' of undefined or null reference JavaScript 运行时错误:无法获取未定义或空引用的属性“removeChild” - JavaScript runtime error: Unable to get property 'removeChild' of undefined or null reference JavaScript运行时错误:无法获取未定义或空引用的属性“值” - JavaScript runtime error: Unable to get property 'value' of undefined or null reference JavaScript运行时错误:无法获取未定义或空引用的属性“msie” - JavaScript runtime error: Unable to get property 'msie' of undefined or null reference javascript运行时错误:无法获取未定义或空引用的属性“替换” - javascript runtime error: unable to get property 'replace' of undefined or null reference JavaScript运行时错误:无法获取未定义或空引用的属性“选项” - JavaScript runtime error: Unable to get property 'options' of undefined or null reference JavaScript运行时错误无法获取未定义或空引用的属性“值” - JavaScript runtime error Unable to get property 'value' of undefined or null reference JavaScript运行时错误:无法获取未定义或空引用的属性“ top” - JavaScript runtime error: Unable to get property 'top' of undefined or null reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM