JavaScript delegates (Delegate) blur and focus usage examples Analysis _javascript skills

Source: Internet
Author: User

This example describes the JavaScript delegate (Delegate) Blur and focus usage. Share to everyone for your reference. The specific analysis is as follows:

Opera (9.5b) for all focus and blur events, can not be correctly triggered two times;
Therefore, the processing functions of the focus and blur events can be delegated to the capture phase of the event.

Example 1 (List Class):

Copy Code code as follows:
<ol id= "List" >
<li><a href= "#" > List Items 1</a>
<ol>
<li><a href= "#" > List Items 1.1</a></li>
<li><a href= "#" > List Items 1.2</a></li>
<li><a href= "#" > List Items 1.3</a></li>
</ol>
</li>
Other list items
</ol>

Example 2 (Form Class):

Copy Code code as follows:
<form id= "Form" >
<input type= "text" id= "textbox"/>
Other table Items
</form>

Here we are listening to the outermost ol block, if we use blur and focus events, just for this whole ol, then inside the control of the focus and Blur events how to deal with it?

The processing method is as follows:

IE Processing:

Copy Code code as follows:
$ (' list '). onmouseover = Handlemouseover;
$ (' list '). onmouseout = Handlemouseout;
$ (' list '). Onfocusin = Handlemouseover;
$ (' list '). Onfocusout = Handlemouseout;

It can also be written in the following form:

Copy Code code as follows:
$ (' list '). attachevent (' Onfocusout ', handlemouseout,true);

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

Copy Code code as follows:
$ (' list '). attachevent (' Onfocusout ', function (event, myparams) {handlemouseout (event, myparams);},true);

FF Processing:

Copy Code code as follows:
$ (' list '). AddEventListener (' Focus ', handlemouseover,true);
$ (' list '). AddEventListener (' Blur ', handlemouseout,true);

I hope this article will help you with your JavaScript programming.

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.