为什么这个'onClick disable = true; this.form.submit();”在一个按钮上工作,但不是另一个? [英] Why does this 'onClick disable=true; this.form.submit();' work on one button but not another?

查看:79
本文介绍了为什么这个'onClick disable = true; this.form.submit();”在一个按钮上工作,但不是另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 < form action =timestable_update.php> 
< input type =submitvalue =Bank Your Scorename =submitbtnonclick =this.disabled = true; this.form.submit();>
< / form>

此代码无效(我正在查看id =btn按钮).. 。发生的一切是按钮禁用,但没有发生提交...

 < form method =postaction = timestable_submit.php > 

< input type =hiddenname = b value =<?php echo $ f;>>>
< input type =hiddenname = c value =<?php echo $ s;?>>
< input type =submitname =submitid =btnvalue =<?php echo $ d;?> onclick =this.disabled = true; this.form.submit();>
< input type =submitname =submitid =btn2value =<?php echo $ w1e;?>>

< input type =submitname =submitid =btn3value =<?php echo $ w2e;?>>
< / form>

任何想法为什么?

这是完整的代码...

 < html> 
< head>
<!--------------定时器---------------->
< script type =text / javascript>
var interval;
var minutes = 0;
var seconds = 05;
window.onload = function(){
countdown('secondsleft');


函数countdown(元素){
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 =秒;
秒 - ;
},1000);
}
< / script>

<!------------------定时器结束------------>
< style>
input [type ='submit'] {
position:absolute;
width:300;
身高:50;
颜色:白色;
背景:红色;
font-size:100%;
}
< / style>


< / head>
< body>

等级:1< br>工作人员,您的得分至今为:0
< br>点击答案:2x11

< form method =postaction =timestable_submit.php>

< input type =hiddenname =bvalue =2>
< input type =hiddenname =cvalue =11>
< input type =submitname =submitid =btnvalue =22onclick =this.disabled = true; this.form.submit();>
< input type =submitname =submitid =btn2value =100>

< input type =submitname =submitid =btn3value =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>


解决方案

问题在于第二个按钮上的名称=提交属性。这会导致Chrome出现问题,因为它会覆盖表单的 submit()函数,导致FirstOne在他的评论中观察到的错误:

 未捕获的TypeError:this.form.submit不是函数

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


This code 'works' - the button is disabled and the form submits. Happy days.

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

This code doesn't work (I'm looking at id="btn" button)... all that happens is that the button disables, but no submit happens...

<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>

Any ideas as to why?

This is the code in it's entirety...

<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>

解决方案

The issue lies with the name="submit" attribute on the second button. This causes an issue with Chrome, as it overrides the submit() function for your form, resulting in the error that FirstOne has observed in his comment:

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

If you choose a different name (as you did for your first button) then it should work ok.

这篇关于为什么这个'onClick disable = true; this.form.submit();”在一个按钮上工作,但不是另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆