Example of how to use javascript Delegate (Delegate) blur and focus _ javascript skills

Source: Internet
Author: User
This article mainly introduces the use of javascript Delegate blur and focus. The example analyzes the usage of javascript Delegate and the usage skills for common browsers, for more information about how to use the javascript Delegate blur and focus, see the example in this article. Share it with you for your reference. The specific analysis is as follows:

Opera (9.5b) cannot correctly trigger all focus and blur events twice;
Therefore, the focus and blur event processing functions can be delegated to the event capture phase.

Example 1 (List class ):

The Code is as follows:


  1. List item 1

    1. List item 1.1

    2. List item 1.2

    3. List item 1.3



  2. Other list items

Example 2 (Form class ):

The Code is as follows:

Here we listen to the ol block on the outermost layer. If we use the blur and focus events, we only target the entire ol block, so how to deal with the focus and blur events of the controls in it?

The processing method is as follows:

IE processing:

The Code is as follows:

$ ('LIST'). onmouseover = handleMouseOver;
$ ('LIST'). onmouseout = handleMouseOut;
$ ('LIST'). onfocusin = handleMouseOver;
$ ('LIST'). onfocusout = handleMouseOut;

You can also write it in the following format:

The Code is as follows:

$ ('LIST'). attachEvent ('onfocusout', handleMouseOut, true );

If you want to pass parameters, you can add an intermediate function, such

The Code is as follows:

$ ('LIST'). attachEvent ('onfocusout', function (event, myparams) {handleMouseOut (event, myparams);}, true );

FF processing:

The Code is as follows:

$ ('LIST'). addEventListener ('core', handleMouseOver, true );
$ ('LIST'). addEventListener ('blur', handleMouseOut, true );

I hope this article will help you design javascript programs.

Related Article

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.