我需要在电子邮件地址重复时显示提醒信息。
这是我的代码:
$.validator.addMethod("contactpersonen-email", function(value, element) {
var parentForm = $(element).closest('form');
var timeRepeated = 0;
if (value != '') {
$(parentForm.find(':text')).each(function () {
if ($(this).val() === value) {
timeRepeated++;
}
});
}
return timeRepeated === 1 || timeRepeated === 0;
alert('duplicate');
}, "Email adres bestaat al");
但它不起作用。你能找出问题并让它发挥作用吗?
答案 0 :(得分:1)
$.validator.addMethod("contactpersonen-email", function(value, element) {
var parentForm = $(element).closest('form');
var timeRepeated = 0;
if (value != '') {
$(parentForm.find(':text')).each(function () {
if ($(this).val() === value) {
timeRepeated++;
}
});
}
var ok = timeRepeated === 1 || timeRepeated === 0;
if(!ok) alert('duplicate');
return ok;
}, "Email adres bestaat al");