「JavaScript」onkeydownのサンプルコード

書式
document.getElementById(selectorId).onkeydown =
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<input id="usrId" type="text" value="" maxlength="5" autocomplete="off">
<script>
document.getElementById("usrId").onkeydown = function(event){
if (event.key === "Backspace"){
console.log("Backspace key is pressed");
return false;
}
}
</script>
<input id="usrId" type="text" value="" maxlength="5" autocomplete="off"> <script> document.getElementById("usrId").onkeydown = function(event){ if (event.key === "Backspace"){ console.log("Backspace key is pressed"); return false; } } </script>
<input id="usrId" type="text" value="" maxlength="5" autocomplete="off">
<script>
document.getElementById("usrId").onkeydown = function(event){
      if (event.key === "Backspace"){
      console.log("Backspace key is pressed");
      return false;
      }
}
</script>

 

JavaScript

Posted by arkgame