如何在javascript中为按钮添加一次单击和下一次单击的功能

如何在javascript中为按钮添加一次单击和下一次单击的功能,javascript,html,Javascript,Html,在这里我附上我的代码告诉我,按钮如何执行功能,并立即禁用,直到它刷新,我还必须为它设置计时器 请帮助如何做到这一点,我有不同大小的表来执行,所以当一个按钮正在执行一些其他按钮不应该工作 <html> <head> <script type="text/javascript"> function boardSize(id, btnid) { function hitheadr(id, bt

在这里我附上我的代码告诉我,按钮如何执行功能,并立即禁用,直到它刷新,我还必须为它设置计时器

请帮助如何做到这一点,我有不同大小的表来执行,所以当一个按钮正在执行一些其他按钮不应该工作

<html>
   <head>
    <script type="text/javascript">

                function boardSize(id, btnid) {

            function hitheadr(id, btnid) {

                return function () {
                    console.log(id);
                };
                 document.getElementByid(btnid).disabled=true;
            }`
            function createTable(rows, cols, element) {
                function getButtonId(i, j) {
                    return 'hit'
                }
               var table = document.createElement('table'),
                    tr, td, button, i, j,
                    colors = ["red", "blue", "yellow"];

                for (i = 0; i < rows; i++) {
                    tr = document.createElement('tr');

                    for (j = 0; j < cols; j++) {
                        td = document.createElement('td');
                        button = document.createElement('button');
               button.style.backgroundColor  =colors[Math.floor(Math.random() * colors.length)];
                        button.appendChild(document.createTextNode(getButtonId(i, j)));
                        button.onclick = hitheadr(getButtonId(i, j));
                        button.id = getButtonId(i, j);
                        button.onclick = onBtnClick;

                                               button.id = getButtonId(i, j);
                        td.appendChild(button);
                        tr.appendChild(td);
                    }
                    table.appendChild(tr);
                    table.setAttribute("align", "center");
                    tr.setAttribute("border", "2");
                }
                element.appendChild(table);
            }

            createTable(3, 3, document.body);
        }

    </script> 
</head>

功能板大小(id,btnid){
功能HITHEARD(id,btnid){
返回函数(){
console.log(id);
};
document.getElementByid(btnid).disabled=true;
}`
函数createTable(行、列、元素){
函数getButtonId(i,j){
返回“命中”
}
var table=document.createElement('table'),
tr,td,button,i,j,
颜色=[“红色”、“蓝色”、“黄色”];
对于(i=0;i


使用以下代码,您可以禁用按钮单击。 单击按钮后,此脚本将禁用下一次按钮单击,直到刷新页面。

功能板尺寸(id,btnid){
功能HITHEARD(id,btnid){
返回函数(){
console.log(id);
};
document.getElementByid(btnid).disabled=true;
}`
函数createTable(行、列、元素){
函数getButtonId(i,j){
返回“命中”
}
var table=document.createElement('table'),
tr,td,button,i,j,
颜色=[“红色”、“蓝色”、“黄色”];
对于(i=0;i
            function boardSize(id, btnid) {

        function hitheadr(id, btnid) {

            return function () {
                console.log(id);
            };
             document.getElementByid(btnid).disabled=true;
        }`
        function createTable(rows, cols, element) {
            function getButtonId(i, j) {
                return 'hit'
            }
           var table = document.createElement('table'),
                tr, td, button, i, j,
                colors = ["red", "blue", "yellow"];

            for (i = 0; i < rows; i++) {
                tr = document.createElement('tr');

                for (j = 0; j < cols; j++) {
                    td = document.createElement('td');
                    button = document.createElement('button');
           button.style.backgroundColor  =colors[Math.floor(Math.random() * colors.length)];
                    button.appendChild(document.createTextNode(getButtonId(i, j)));
                    button.onclick = hitheadr(getButtonId(i, j));
                    button.id = getButtonId(i, j);
                    button.onclick = onBtnClick;

                                           button.id = getButtonId(i, j);
                    td.appendChild(button);
                    tr.appendChild(td);
                }
                table.appendChild(tr);
                table.setAttribute("align", "center");
                tr.setAttribute("border", "2");
            }
            element.appendChild(table);
        }

        createTable(3, 3, document.body);
    }

</script>