0
我得到如何检查输入是否填充,但是,如何检查输入未填充?Jquery验证使用依赖和检查未填充
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() == '';
}
}
}
}
但有没有运气无论是。那么我怎样才能使这个工作?谢谢。
首先,你必须关闭括号缺失 '返回($('#current_email')。val()=='';' – UnLoCo 2012-08-06 21:35:38
甜......谢谢 – 2012-08-07 18:13:59
这就是答案,所以如果你这样做,它会被检查回答 – 2012-08-09 02:48:46