簡體   English   中英

jQuery驗證規則取決於生成未捕獲的TypeError

[英]Jquery Validation Rule Depends Generates Uncaught TypeError

當我嘗試使用jQuery驗證規則時,取決於以下內容:

<script>
$('#sign-up-form form').validate({
    rules: {
        state: "required",
        school: {
            depends: function(element) {
                return $("#id_school_id").val().length;
                }
            }
    }
});
</script>

每次規則的依賴部分運行時,我都會得到Uncaught TypeError: Cannot read property 'call' of undefined

我要檢查的ID在那兒(#id_school_id)。 我正在使用jquery.validation.js v 1.11.1

我誤會了,要說是規則方法。 您需要將其值應用於規則方法。 因此,例如

$('#sign-up-form form').validate({
rules: {
    state: "required",
    school: {
        required: {
            depends: function(element) {
                return $("#id_school_id").val().length;
            }
        }
    }
},
messages: {
    school: "Please choose a valid school name from the choices presented"
}
});

</script>

是否需要字段“學校”取決於字段“ school_id”的長度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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