繁体   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