1

好吧,我开发了一个简单的字段验证脚本注册,并想使如果有一些错误,一些空白,被禁用按钮发送表单。

我有几个字段,如果一个或全部为空,则发送按钮被禁用。

我的脚本的一部分:

$('#tipo_pessoa').focusout(function () {
    if ($(this).val() == '') {
        $(this).toggleClass('inputs_error-select')
        $("label[for='tipo_pessoa']").fadeIn().html('<img src="../imagens/error.png" align="absmiddle" />&nbsp;Campo obrigatório');

        ErrorSound();
    } else {
        $(this).toggleClass('inputs, inputs_error-select')
        $("label[for='tipo_pessoa']").text('');

    }
});


$('#razao_social').focusout(function () {
    if ($(this).val() == '' || $(this).val() == $(this).attr("placeholder")) {
        $(this).removeClass('inputs').addClass('inputs_error');
        $("label[for='razao_social']").fadeIn().html('<img src="../imagens/error.png" align="absmiddle" />&nbsp;O Campo Razão Social deve ser preenchido');
        ErrorSound();
    } else {
        $(this).removeClass('inputs_error').addClass('inputs');
        $("label[for='razao_social']").text('');

    }
});

我需要一个脚本来计算/检查任何错误,如果有任何一个或多个错误,提交按钮被禁用

4

1 回答 1

1

当有空字段时,您可以阻止表单提交:

$('form').submit(function(e){
   return $('#input1, #input2').filter(function() {
      return $.trim(this.value).length === 0;
   }).length === 0;
});
于 2012-05-19T16:51:07.130 回答