<form name="name" action="a.php" method="get">
<input type="text" name="abbb" value="" />
<input id="ab" type="submit" name="submitform" onclick="return checkform()" value="提交" />
</form><script type="text/javascript">
function checkform() {
document.getElementById("ab").disabled = "disabled";
return true;
}
</script>上面的代码只能在火狐下工作,其它浏览器都不能提交,提交按钮变灰之后就没有动静了
如果使用jquery,把“document.getElementById("ab").disabled="disabled"改成“$("#ab").disabled="disabled"”就没有问题了。
问题是,为什么用document.getElementById就不行呢?
请问有谁可以帮我找到是什么原因吗?
<input type="text" name="abbb" value="" />
<input id="ab" type="submit" name="submitform" onclick="return checkform()" value="提交" />
</form><script type="text/javascript">
function checkform() {
document.getElementById("ab").disabled = "disabled";
return true;
}
</script>上面的代码只能在火狐下工作,其它浏览器都不能提交,提交按钮变灰之后就没有动静了
如果使用jquery,把“document.getElementById("ab").disabled="disabled"改成“$("#ab").disabled="disabled"”就没有问题了。
问题是,为什么用document.getElementById就不行呢?
请问有谁可以帮我找到是什么原因吗?
这样就好了。。
能不能请你解释一下呢?
<form name="name" action="a.php" method="get" onsubmit="return checkform()">
<input type="text" name="abbb" value="" />
<input id="ab" type="submit" name="submitform" value="提交" />
</form><script type="text/javascript">
function checkform() {
document.getElementById("ab").disabled = "disabled";
return true;
}
</script>
document.getElementById("ab").disabled = "disabled";
document.name.submit()
return true;
}
多谢chinaskysun,我认为这个方法是最好的,在form的submit事件发生时判断。
多谢showbo,这个方法也可以,但不知道form的submit事件会不会在火狐中发生2次,我测试了一下,请求发生1次。
也多谢plzzz,先提交再禁用也可以,我能想出来的代码是把showbo的提交和禁用调换。