<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就不行呢?
请问有谁可以帮我找到是什么原因吗?

解决方案 »

  1.   

    document.getElementById("ab")[0].disabled = "disabled";
    这样就好了。。
      

  2.   

    多谢啦,试过之后,确实可以,但却不明白加了个[0]是什么意思,我调试了一下,在所有浏览器中返回的都是object,加[0]显示的是undefined。
    能不能请你解释一下呢?
      

  3.   

    楼主的方法不好,用这种
    <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>
      

  4.   

        function checkform() {
            document.getElementById("ab").disabled = "disabled";
            document.name.submit()
            return true;
        }
      

  5.   

    多谢pxy1510742,这个方法可以,但不知道为何要这样。
    多谢chinaskysun,我认为这个方法是最好的,在form的submit事件发生时判断。
    多谢showbo,这个方法也可以,但不知道form的submit事件会不会在火狐中发生2次,我测试了一下,请求发生1次。
    也多谢plzzz,先提交再禁用也可以,我能想出来的代码是把showbo的提交和禁用调换。