状态为0时如何提交表单?
$(".form-validation").submit(function(e) {
e.preventDefault();
//check requst product blank field
var Status = 0;
$('.requiredCheck').each(function() {
var blank_value = $.trim($(this).val());
var blank_attr = $(this).attr('name');
if (!blank_value) {
Status = 1;
$(this).css('border-color', 'red');
} else {
$(this).css('border-color', '');
}
});
if (Status == 1) {
$('.status-message').html('<span style="color:red;">(*) Marks field are mandatory to fill up** *</span>');
return false;
} else {
console.log('ready to submit')
//$(this).find(":submit").prop('disabled', true);
//$('input:submit').trigger("click");
return true;
}
});
答案 0 :(得分:0)
在第2行中注释e.preventDefault()
,并将其移至if (Status == 1)
下面是修改后的代码
$(".form-validation").submit(function(e) {
//e.preventDefault();
//check requst product blank field
var Status = 0;
$('.requiredCheck').each(function() {
var blank_value = $.trim($(this).val());
var blank_attr = $(this).attr('name');
if (!blank_value) {
Status = 1;
$(this).css('border-color', 'red');
} else {
$(this).css('border-color', '');
}
});
if (Status == 1) {
$('.status-message').html('<span style="color:red;">(*) Marks field are mandatory to fill up** *</span>');
e.preventDefault();
return false;
} else {
console.log('ready to submit')
//$(this).find(":submit").prop('disabled', true);
//$('input:submit').trigger("click");
return true;
}
});