Javascript 使用setTimeout为按钮添加冷却时间

Javascript 使用setTimeout为按钮添加冷却时间,javascript,button,settimeout,Javascript,Button,Settimeout,我尝试创建一个名为coolDown的对象方法,当单击一个按钮时,它将禁用该按钮,并在冷却时间结束后将其解锁 但是当我测试它时,它会禁用按钮,但是,在冷却时间结束后没有解锁按钮,这是为什么 var btncd = new test(); function test() { } test.prototype.coolDown = function() { document.getElementById("cd").disabled = "true"; setTimeout(fun

我尝试创建一个名为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

是的,我将disabled属性设置为false,这是否意味着已删除?
disabled
应分配
布尔值。字符串
基本上
非空字符串
的计算结果为
true
是!谢谢你的回答!