禁用的输入未启用

问题描述 投票:0回答:1
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
  }
})

此代码将禁用输入,但当要启用它时,它不起作用(控制台显示日志,但这不起作用)

javascript input setattribute
1个回答
0
投票

要再次启用元素,您需要删除该属性:

inputmins.removeAttribute("disabled");
inputtemp.removeAttribute("disabled");
inputhours.removeAttribute("disabled");

或者使用元素禁用属性:

inputmins.disabled = false;
inputtemp.disabled = false;
inputhours.disabled = false;
© www.soinside.com 2019 - 2024. All rights reserved.