当未填写必填字段时,我需要禁用提交按钮。但是脚本不起作用。如果有人可以提供帮助,请提前致谢。
网页:
<input type="submit" value="Submit" name="sub1" id="submit1">
Javascript:
<script language="JavaScript">
function form_valid() {
var u1=document.getElementById("#user1").value;
var p1=document.getElementById("#pass1").value;
var p2=document.getElementById("#pass2").value;
var s1=document.getElementById("#school1").value;
if ((u1 == null)&&(p1 != p2)&&(s1 == null))
{
document.getElementById("#submit1").disabled = true;
document.getElementById("#submit1").setAttribute("disabled","disabled");
}
else
{
document.getElementById("#submit1").disabled = false;
document.getElementById("#submit1").removeAttribute("disabled");
}
}
function form_run() {
window.setInterval(function(){form_valid();}, 1000);
}
</script>
正文标签(HTML):
<body bgcolor="#d6ebff" onload="form_run();">