startbtn.addEventListener("click", () => {
if (startbtnclicked === false) {
time[0] = inputhours.value
time[1] = inputmins.value
temp = inputtemp.value
if (valid(100, temp, time)) {
inputmins.setAttribute("disabled", true)
inputtemp.setAttribute("disabled", true)
inputhours.setAttribute("disabled", true)
console.log("allclear");
clockdisplay.innerText = `${time[0]}:${time[1]}:00`
tempdisplay.innerText = ` ${temp}°C`
countdown(time, clockdisplay)
startbtnclicked = true
} else {
console.log("**** off");
}
} else {
console.log("for **** sake")
inputmins.setAttribute("disabled", false)
inputtemp.setAttribute("disabled", false)
inputhours.setAttribute("disabled", false)
startbtnclicked = false
}
})
此代码将禁用输入,但当要启用它时,它不起作用(控制台显示日志,但这不起作用)
要再次启用元素,您需要删除该属性:
inputmins.removeAttribute("disabled");
inputtemp.removeAttribute("disabled");
inputhours.removeAttribute("disabled");
或者使用元素禁用属性:
inputmins.disabled = false;
inputtemp.disabled = false;
inputhours.disabled = false;