Home >Web Front-end >JS Tutorial >JS sample code for blocking key effects and changing key effects_javascript skills

JS sample code for blocking key effects and changing key effects_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:07:271065browse

Function keys F1-F2: 112-123

a-b: 65-90

Number keys: 0-9: 48-57

ESC: 27

Backspace key: 8

Enter: 13

shift: 16; Ctrl: 17; Alt: 18

Space: 32

Insert: 45; Delete: 46

Copy code The code is as follows:

function document .onkeydown(){ //Triggered by pressing Enter in the webpage
if(event.keyCode==13)
{
document.getElementById("loginbtn").click();
return false;                                         

document.onkeydown=MM_KeyPress;

function MM_KeyPress(num){

//Prevent the system backspace key

var keycode = event.keyCode;

if(keycode ==8)//Shield the backspace key
{

event.keyCode = 0;
//event.returnValue=false;

return;

}
if(keycode >=112 && keycode <=123)//Shield f1 -12 function keys
{

event.keyCode = 0 ;
event.returnValue=false;

return;

}
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn