【发布时间】:2013-07-03 19:12:13
【问题描述】:
我需要禁用提交按钮,直到所有字段都填满规则任何提示?
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 的字段中键入函数运行并启用或不启用提交
【问题讨论】:
-
您可以在 html 中禁用它,然后使用 javascript“启用”。
-
是的,但是我缺少的功能不起作用
-
去掉window.onload这一行
-
没用,代码对吗?我仔细检查了字段 ID,它们是正确的
标签: javascript forms validation