Home  >  Article  >  Web Front-end  >  js implementation example of blocking default shortcut keys for calling custom events_javascript skills

js implementation example of blocking default shortcut keys for calling custom events_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:31:58956browse

For details on how to block more shortcut keys, you can search on Google yourself.
What I want to talk about here is how to block and execute custom events.

For the convenience of use, Kibo is used as an example. The results obtained by searching on Google are generally native JavaScript implementations. It is very simple and will not be introduced here.

Here is an example of saving by enter in a textarea, blocking the original enter event.
The code is as follows:

Copy code The code is as follows:

//Keyboard monitoring
var areaKey = new Kibo($("#aac010")[0]);
areaKey.down('enter',doSave);
function doSave() {
event.keyCode = 0;
event.returnValue = false;
setTimeout(save, 300);
return false;
}

Shielding the original js event is generally keyCode=0, returnValue =false, return false;, the key is how to call a custom method, such as the save method above. If the save method is written directly here, since it takes a certain amount of time to execute save, if false is not returned in a short period of time, it will cause The triggering of the original event of enter cannot function as a shield, so setTimeout is used here to call the custom method. Let returnun return in time so that the original event will not be triggered.

The specific reason is not clear. If anyone has a better method or knows the reason, you can leave a message. Thank you~~~
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