简体   繁体   中英

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. 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

how to handle runtime exception in 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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