5

我有一个包含四个字段的表单。我对其中的 3 个应用了一些不显眼的验证。我希望在执行所有不显眼的验证后调用一个 jquery 函数,但是我onsubmit在表单上定义了一个事件,以便每次它第一次转到该 jquery 函数并执行所有步骤时,然后显示不显眼的验证消息对于相应的文本框。

但是,如果表单已通过不显眼的验证,我想执行 jquery 函数的所有步骤。

有没有办法检查所有不显眼的验证是否已执行?

这是我的jQuery代码:

function submitDetails()
{
var check = $('#flag').val();            
if (check == 1)
{
return true;
}

else {
var birthDate = ($('#BirthDate').val()).split('/');
var graduationDate = ($('#GraduationDate').val()).split('/');
var stdate = birthDate[2] + birthDate[1] + birthDate[0];
var endate = graduationDate[2] + graduationDate[1] + graduationDate[0];
if (($('#LastName').val() == "") || (parseInt(endate) < parseInt(stdate)))
  {
    $('#Window').data('tWindow').center().open();
    return false;
}
else { return true; }
}
}   
4

1 回答 1

10

您可以检查表单在提交处理程序中是否有效:

$('#formId').submit(function() {
    if (!$(this).valid()) {
        // validation failed => here you can call your function or whatever
        return false;
    } else {
        // the form is valid => you could perform some other action if you will
    }
});
于 2011-11-23T07:10:03.613 回答