Example Analysis of the Use of javascript Delegate (Delegate) blur and focus, delegateblur
This article describes how to use the javascript Delegate blur and focus. 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 ):
Copy codeThe Code is as follows: <ol id = "list">
<Li> <a href = "#"> Item 1 </a>
<Ol>
<Li> <a href = "#"> list item 1.1 </a> </li>
<Li> <a href = "#"> list item 1.2 </a> </li>
<Li> <a href = "#"> list item 1.3 </a> </li>
</Ol>
</Li>
Other list items
</Ol>
Example 2 (Form class ):
Copy codeThe Code is as follows: <form id = "form">
<Input type = "text" id = "text box"/>
Other Form Items
</Form>
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:
Copy codeThe 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:
Copy codeThe Code is as follows: $ ('LIST'). attachEvent ('onfocusout', handleMouseOut, true );
If you want to pass parameters, you can add an intermediate function, such
Copy codeThe Code is as follows: $ ('LIST'). attachEvent ('onfocusout', function (event, myparams) {handleMouseOut (event, myparams) ;}, true );
FF processing:
Copy codeThe Code is as follows: $ ('LIST'). addEventListener ('focal ', handleMouseOver, true );
$ ('LIST'). addEventListener ('blur', handleMouseOut, true );
I hope this article will help you design javascript programs.