1

我需要禁用提交按钮,直到所有字段都填满规则任何提示?

window.onload = $("input[type=submit]").attr("disabled", "disabled");
$(function(){   
                    $("input[type=submit]").attr("disabled", "disabled");
                    var total = document.getElementById('valor_total'),
                    descontado = document.getElementById('valor_descontado'),
                    valor_final = document.getElementById('valor_final'),
                    vendedor = document.getElementById('vendedor'),
                    cliente = document.getElementById('cliente'),
                    no_contrato = document.getElementById('contrato'),
                    validation;

                        var f_total = total.value;
                        var f_descontado = descontado.value;
                        var f_final = valor_final.value;
                        var f_vendedor = vendedor.value;
                        var f_cliente = cliente.value;
                        var f_no_contrato = no_contrato.value;

                        $("#numero_contrato").blur(function() {

                        if ( f_vendedor == "0" || f_cliente == "0" || f_no_contrato == "" || f_total == "0,00" || f_final == "0,00") {
                        validation = false;
                        } else {
                        validation = true;
                        }
                        if (validation = true) {
                        $("input[type=submit]").removeAttr("disabled"); 
                        } else {
                        $("input[type=submit]").attr("disabled", "disabled");
                        }
                        });
                });

我做错了什么?

我希望该用户在 id 为 numero_contrato 的字段中键入该函数运行并启用或不启用提交

4

1 回答 1

1

对于初学者,请尝试修复此条件:

if (validation === true) {
     $('input[type=submit]').removeAttr('disabled'); 
} else {
     $('input[type=submit]').attr('disabled', 'disabled');
}

您有一个用于分配的等号。你想要双倍或最好是三倍等于。但是您可以完全放弃这些,因为您使用的是布尔值: if (validation) { ... }

于 2013-07-03T19:18:42.417 回答