[jQuery]keydownでキー入力を無効化するサンプル
書式
$(“#セレクターID").keydown(function(event)
サンプルコード
<input id="usrId" type="text" value="" maxlength="1" autocomplete="off">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$("#usrId").keydown(function(event) {
if (event.key === "Backspace"){
console.log("Backspace key is pressed");
return false;
}
});
</script>
<input id="usrId" type="text" value="" maxlength="1" autocomplete="off">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$("#usrId").keydown(function(event) {
if (event.key === "Backspace"){
console.log("Backspace key is pressed");
return false;
}
});
</script>
<input id="usrId" type="text" value="" maxlength="1" autocomplete="off"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $("#usrId").keydown(function(event) { if (event.key === "Backspace"){ console.log("Backspace key is pressed"); return false; } }); </script>