我有具有相同 onclick 功能的按钮。 我希望单击一次后禁用按钮。 onclick 函数需要执行多个函数,那么我怎样才能实现这一点。
<input type="button" class="buttons" id="button2" value="2"
onclick="run()" />
下面是其中一个按钮的代码,在运行函数中是另一个正在运行的函数。
function disablebutton(button){
this.disabled = true;
}
最佳答案
您只需调用不同按钮上的函数即可。
function disablebutton(buttonObject){
buttonObject.disabled = true;
}
var button1 = document.getElementById('b1');
var button2 = document.getElementById('b2');
button1.onclick = function(){
disablebutton(button1);
}
button2.onclick = function(){
disablebutton(button2);
}
或者
<input type="button" class="buttons" id="button1" value="1"
onclick="run(this)" />
<input type="button" class="buttons" id="button2" value="2"
onclick="run(this)" />
function run(button){
button.disabled = true;
}
关于javascript - 如何在 onclick 之后禁用一个按钮,但它在另一个函数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55654719/