为什么这个“点击禁用=true;this.form.submit();' 在一个按钮上工作,但不能在另一个按钮上工作

Why does this 'onClick disable=true; this.form.submit();' work on one button but not another?

本文关键字:按钮 工作 另一个 但不能 一个 form 点击禁用 为什么 this true submit      更新时间:2023-09-26

此代码"有效" - 按钮被禁用,表单提交。快乐的日子。

    <form action="timestable_update.php">
    <input type="submit" value="Bank Your Score" name="submitbtn" onclick="this.disabled=true; this.form.submit();">
</form>

这段代码不起作用(我正在查看 id="btn" 按钮)...发生的所有情况是按钮禁用,但没有提交发生......

<form method= "post" action="timestable_submit.php">
        <input type="hidden" name=b value=<?php echo $f;?>>
        <input type="hidden" name=c value=<?php echo $s;?>>
        <input type="submit" name="submit" id="btn" value="<?php echo $d;?>" onclick="this.disabled=true; this.form.submit();">
        <input type="submit" name="submit" id="btn2" value="<?php echo $w1e;?>">
        <input type="submit" name="submit" id="btn3"  value="<?php echo $w2e; ?>">
        </form>

关于为什么的任何想法?

这是完整的代码...

<html>
    <head>
        <!--------------timer---------------->
       <script type="text/javascript">
        var interval;
        var minutes = 0;
        var seconds = 05;
        window.onload = function () {
            countdown('secondsleft');
        }
        function countdown(element) {
            interval = setInterval(function () {
                var el = document.getElementById(element);
                if (seconds == 0) {
                     el.innerHTML = "Time is Up!"; 
                    window.location.assign("timestable_timeout.php")
                    if (minutes == 0) {
                        clearInterval(interval);
                        return;
                    } else {
                        minutes--;
                        seconds = 60;
                    }
                }
                el.innerHTML = seconds;
                seconds--;
            }, 1000);
        }
    </script>
        <!------------------ timer end ------------>
        <style>
            input[type='submit']{
                position: absolute;
                width: 300;
                height: 50;
                color: white;
                background: red;
                 font-size:100%;
            }
        </style>

                </head>
    <body>
        Level: 1<br>Staff, your score so far is: 0      
        <br>Click on the answer to:     2x11    
        <form method= "post" action="timestable_submit.php">
        <input type="hidden" name="b" value="2">
        <input type="hidden" name="c" value="11">
        <input type="submit" name="submit" id="btn" value="22" onclick="this.disabled=true; this.form.submit();">
        <input type="submit" name="submit" id="btn2" value="100">
        <input type="submit" name="submit" id="btn3"  value="30">
        </form>
        <!------ timer----->
        <h1><div id="secondsleft"></div></h1>

    <script>
var btn = document.getElementById("btn");
btn.style.top = 553+ "px";
btn.style.left = 408 + "px";
var btn2 = document.getElementById("btn2");
btn2.style.top = 452+ "px";
btn2.style.left = 290 + "px";
var btn3 = document.getElementById("btn3");
btn3.style.top = 503+ "px";
btn3.style.left = 542 + "px";
        </script>
</body></html>

问题出在第二个按钮上的 name="submit" 属性上。 这会导致Chrome出现问题,因为它会覆盖表单的submit()功能,从而导致FirstOne在他的评论中观察到的错误:

Uncaught TypeError: this.form.submit is not a function

如果您选择其他名称(就像您对第一个按钮所做的那样),那么它应该可以正常工作。