我有几个禁用所有提交按钮的文本框,除非它们都被填满。我也有一个dropdwon列表,但是在用户选择之前不会禁用“提交”按钮。如何禁用提交按钮,直到所有字段都填满并满足要求?请帮助
<html>
<head>
<script>
function success() {
if (document.getElementById("uname").value === "" || document.getElementById("age").value === "" || document.getElementById("sex").selectValue == "Please Select") {
document.getElementById('submit_form').disabled = true;
} else {
document.getElementById('submit_form').disabled = false;
}
}
</script>
<style>
</style>
</head>
<body>
Name: <input type="text" id="uname" onkeyup="success()"/> Age: <input type="text" id="age" onkeyup="success()"/> Sex:
<select id="sex" name="sex">
<option value="" selected="selected"> Please Select </option>
<option value="Male"> Male </option>
<option value="Female"> Female </option>
</select>
<input type="submit" name="submit" id="submit_form" value="Submit" disabled>
</body>
</html>
答案 0 :(得分:0)
document.addEventListener("input", function() {
if (
document.getElementById("uname").value == "" ||
document.getElementById("age").value == "" ||
document.getElementById("sex").value == ""
) {
document.getElementById("submit_form").disabled = true;
} else {
document.getElementById("submit_form").disabled = false;
}
});
答案 1 :(得分:0)
在jquery中,您可以使用“ prop”功能禁用选择框:
<script>
$('#select_id').prop('disabled', 'disabled');
</script>
要禁用文本框,您可以使用jquery将“只读”属性添加到元素:
<script>
$("#textboxid").attr("readonly");
</script>