简体   繁体   English

刷新页面时,“提交”按钮不起作用-javascript

[英]Submit button not working when the page is refreshed -javascript

The code is given below: 代码如下:

    <button type="button" class = "butt1" id ="submit" name ="submit" onclick="myAns(); this.disabled = true;"> Answer </button>

<script>
        function myAns(){
        for(var t=0; t <=count-1; t++) { 
        var table = document.getElementById("tableid");
        var row = table.insertRow(t);
            var cell1 = row.insertCell(0);
            cell1.innerHTML =array[t];

            }
    }
</script>
  1. I am trying to make sure submit button works only once when clicked. 我试图确保“提交”按钮在单击时仅起作用一次。
  2. The given code above works fine with chrome, if the page is refreshed, you can click once more. 上面给定的代码适用于chrome,如果刷新页面,则可以再次单击。
  3. In firefox, the given code also works once if the page is not refreshed. 在firefox中,如果未刷新页面,则给定的代码也可以运行一次。
  4. In firefox, if the page is refreshed,you cannot click again. 在Firefox中,如果刷新页面,则无法再次单击。 Can anyone provide the solution or show a way to do so? 谁能提供解决方案或显示出解决方案?
  5. Basically, I want to make sure the submit button is clickable only once at each refresh. 基本上,我想确保每次刷新时都只能单击一次提交按钮。 The code is fine for Chrome but I need a solution at FireFox. 该代码适用于Chrome,但我需要FireFox的解决方案。

Your problem is here: 您的问题在这里:

cell1.innerHTML =array[t];

change to this: 更改为此:

cell1.innerHTML = t;

 <table id="tableid"> <tr> <td>1</td> </tr> </table> <button id="submit" onclick="a(event)">Click Me!</button> <script> document.getElementById('submit').removeAttribute('disabled'); function a(e) { for (var t = 0; t <= 5 - 1; t++) { var table = document.getElementById("tableid"); var row = table.insertRow(t); var cell1 = row.insertCell(0); cell1.innerHTML = t; } e.target.setAttribute('disabled', 'disabled'); } </script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM