<div class="login-form">
<form action="page.jsp" id="form-id" method="post" novalidate="novalidate">
<div> <input type="text" name="Email" id="emaiphys" style="max-width: 320px;"><span id="label-span"></span></div>
<input class="btn" type="submit" value="RESET PASSWORD">
<a href="./login.jsp">Return to Login</a>
</form>
</div>
我正在使用 jquery 验证来验证电子邮件字段。以下是我的 jquery 验证代码
(function($,W,D)
{
var JQUERY4U = {};
JQUERY4U.UTIL =
{
setupFormValidation: function()
{
//form validation rules
$("#form-id").validate({
errorClass:"errorClass",
errorElement:"label",
rules: {
Email: {
required: true,
email: true,
remote:"./check-email.jsp"
}
},
messages: {
Email: {
required: "Please enter a Email Address",
email: "Please enter a Valid Email Address",
remote: "Email not found"
}
},
highlight:function(element,errorClass){
$(element).removeClass(errorClass);
},
errorPlacement: function(error, element) {
//alert(element.parent());
error.appendTo( element.next());
},
submitHandler: function(form) {
form.submit();
},
success: function(label) {
// set as text for IE
label.addClass('checked');
}
});
}
}
//when the dom has loaded setup form validation rules
$(D).ready(function($) {
JQUERY4U.UTIL.setupFormValidation();
});
})(jQuery, window, document);
如果成功,则会显示在 css 类中定义的“tick”图像。现在,如果用户再次输入不正确的电子邮件,则检查的类仍然存在,这会导致“tick”图像再次可见,以防出现错误。那么,一旦输入了正确的电子邮件,当用户输入不正确的 emnail 时,如何删除已检查的类。