簡體   English   中英

在ko.observable字段上處理異常“ JavaScript運行時錯誤:無法獲取未定義或空引用的屬性'length'”?

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

我在注冊表上使用Knockoutjs。 用戶單擊按鈕以顯示密碼字段時出現運行時錯誤

JavaScript運行時錯誤:無法獲取未定義或空引用的屬性“ length”

如何處理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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM