Copy code code as follows:
<script language = "javascript">
Function GetInput () {// Shield non -digital and non -retreating fabrics
var k = event.keycode; // 48-57 is the number key to large keyboards, 96-105 is the number key for small keyboards, 8 is a retreat symbol ←
if ((k <= 57 && k> = 48) || (k <= 105 && k> = 96) || (k == 8) {
Return true;
} Else {
Return false;
}
}
Function set (obj) {
// Treat the content of the input box in the real time, such as performing certain operations
}
</script>
<input type = 'text' value = '1' Onkeydown = 'Return GetInput ()' onkeyup = 'Set (this)'>
Technical essentials: The onkeydown event is triggered before the onKeyup event; when the onkeydown event Return False will not be triggered, and there will be no user just pressing the characters in the input box, thereby realizing that some characters are shielded to some characters. Purpose. Understanding the principle of triggering this incident, it should be extended in mind (such as several incidents in the mouse will also be such a mechanism) ...