Js implementation shield default shortcut key call Custom Event example

Source: Internet
Author: User

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 ~~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.