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):
- List item 1
;
;
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:
$('List').onfocusin = handleMouseOver;
$('List').onfocusout = handleMouseOut;
can also be written in the following form:
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.