[英]Is there a way to add a cooldown to my code using setTimeout so that people don't spam the command?
[英]Using setTimeout to add cooldown time to a button
我尝试创建一个名为coolDown的对象方法,当单击一个按钮时,它将在冷却时间结束后禁用该按钮并将其解锁。
但是当我测试它时,它将禁用按钮,但是,在冷却时间结束后却没有解锁按钮,为什么?
var btncd = new test();
function test() {
}
test.prototype.coolDown = function() {
document.getElementById("cd").disabled = "true";
setTimeout(function() {document.getElementById("cd").disabled = "false";}, 2000);
}
window.onload = function() {
document.getElementById("cd").onclick = btncd.coolDown;
}
感谢您的回答。
它应该是
document.getElementById("cd").disabled = false; // without ""
Boolean("false");
被评估为true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.