📌  相关文章
📜  检测按退格键的事件监听器 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:26.982000             🧑  作者: Mango

代码示例1
document.addEventListener("keydown", function(event) 
{
  if (event.key == "c") 
  {
    console.log("C Pressed");
    document.getElementById("btnConvert").click();
  }

  var convertButton = document.getElementById("btnConvert");
  if (event.key == "Backspace") 
  {
    console.log("Backspace Pressed");
    var textboxContent = document.getElementById("txtFahrenheit").value;
    if (textboxContent.value == "" || textboxContent.value == "-")
    {
      convertButton.disabled = true;
    }
  }
})

/*HTML:


*/