「JavaScript」onkeydownのサンプルコード
書式
document.getElementById(selectorId).onkeydown =
サンプルコード
<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>