You can search for more shortcuts by google.
Here we will talk about how to block and then execute custom events.
Here, we use Kibo for ease of use as an example. The results searched by google are generally implemented in javascript native, which is very simple and will not be introduced here.
Here is an example of saving enter in a textarea to block the original carriage return event.
The Code is as follows:
Copy codeThe Code is as follows:
// Keyboard listener
Var areaKey = new Kibo ($ ("# aac010") [0]);
AreaKey. down ('enter', doSave );
Function doSave (){
Event. keyCode = 0;
Event. returnValue = false;
SetTimeout (save, 300 );
Return false;
}
To shield original js events, it is generally implemented by keyCode = 0, returnValue = false, and return false;. The key is how to call a custom method, as shown in the save method above, if you directly write the save method here, because it takes some time to execute save and false is not returned for a short time, the original event of enter will be triggered and cannot be blocked, therefore, setTimeout is used to call the custom method. Let the returun return in time so that the original event will not be triggered.
The specific reason is unclear. If someone has a better method or knows the reason, leave a message. Thank you ~~~