我有一个表格,我正在使用 focusin 和 focusout 事件并验证 focusout。我一开始禁用了提交按钮,我想在验证后再次启用它。这是我的代码。
$("document").ready(function() {
$("#contact_submit").attr("disabled", "disabled");
$("#first_name").focusin(function() {
$("#Frist_name_comment").html('Please inter your first name.');
}).focusout(function() {
var first_name = $("#first_name").val();
if(first_name == "") {
$("#Frist_name_comment").html("First Name is required.");
}else {
$("#Frist_name_comment").html('OK');
}
});
$("#last_name").focusin(function() {
$("#Last_name_comment").html('Please inter your last name.');
}).focusout(function() {
var last_name = $("#last_name").val();
if(last_name == "") {
$("#Last_name_comment").html("Last Name is required.");
}else {
$("#Last_name_comment").html('OK');
}
});
$("#email").focusin(function() {
$("#Email_comment").html('Please inter a email address.');
}).focusout(function() {
var email = $("#email").val();
var atpos = email.indexOf("@");
var dotpos = email.lastIndexOf(".");
if((email == "" || atpos < 1 || dotpos < atpos+2 || dotpos+2 > email.length)) {
mess == "Not a vallied email.";
$("#Email_comment").html("Not a valied email.");
}else {
$("#Email_comment").html('OK');
}
});
// hear i want to enable submit button after all validation
});