Home > Web Front-end > JS Tutorial > JavaScript delegate (Delegate) blur and focus usage example analysis_javascript skills

JavaScript delegate (Delegate) blur and focus usage example analysis_javascript skills

WBOY
Release: 2016-05-16 15:57:39
Original
1360 people have browsed it

The example in this article describes the usage of javascript delegate (Delegate) blur and focus. Share it with everyone for your reference. The specific analysis is as follows:

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

Example 1 (list class):

Copy code The code is as follows:

  1. List item 1

                                                                                        ;                                                                                                        ;                                                                                                      


  2. Other list items



Example 2 (form class):


Other form items



What we are monitoring here is the outermost ol block. If we use blur and focus events, it is only for the entire ol, so how to deal with the focus and blur events of the controls inside?
The processing method is as follows:

IE processing:


Copy code The code is as follows:$('list').onmouseover = handleMouseOver; $('list').onmouseout = handleMouseOut;
$('List').onfocusin = handleMouseOver;
$('List').onfocusout = handleMouseOut;


can also be written in the following form:


Copy code The code is as follows:$('list').attachEvent('onfocusout',handleMouseOut,true);
If you want to pass parameters, you can add an intermediate function, such as


Copy code The code is as follows:$('list').attachEvent('onfocusout',function(event, myparams ){handleMouseOut(event, myparams);},true);
FF processing:


Copy code The code is as follows:$('list').addEventListener('focus',handleMouseOver,true); $('list').addEventListener('blur',handleMouseOut,true);

I hope this article will be helpful to everyone’s JavaScript programming design.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template