簡體   English   中英

jQuery使用Depends驗證並檢查未填充

[英]Jquery validate using depends and checking not filled

我得到了如何檢查輸入是否已填充的方法,但是,如何檢查輸入是否未填充?

rules: {
    new_email:          {required: "current_email:filled"}
}

如果填寫current_email字段,則將需要new_email字段。 但是我想檢查一下該字段是否為空,然后將其設為必需。 推理:

如果存在這樣的數據,我將從數據庫中返回current_email的值。 如果是這樣,則存在現有的電子郵件,並且不需要用戶添加new_email。 如果數據庫中有一個空值,則current_email字段中將沒有任何內容,從而迫使用戶輸入new_email。

現在,依靠我已經嘗試過:

rules: {
    new_email:{
               required: {
                   depends: function(element) {
                       return ($('#current_email').val() == '';
                   }
               }
              }
}

但是那里也沒有運氣。 那么我將如何使其工作呢? 謝謝。

通過上方的@UnLoCo:

“首先,您有一個右括號,缺少返回值($('#current_email')。val()==”;“

暫無
暫無

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

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