jQuery Listen 介绍
The release shown below is not the last. Please
check1.0.3 instead.
This plugin brings a clean, light solution, to websites with dynamic loaded
content, or full of event bindings.
Intead of bound, handlers for events, are registered along with matching
selectors.
And they’ll still work for new added content.
This is achieved, using Event
delegation, so the plugin will only work for events that
bubble.
Update: jQuery.Listen can Now handle both focus and blur events
thanks to the focusin/focusout workaround.
Many thanks to Jörn Zaefferer for lending me the
code!.
The plugin supports these kind of selectors:
- #id
- nodeName
- .class
- nodeName.class
- a comma-separated selector combining these 4.
I plan to add more support, but perfomance and scalability are my priorities.
These simple selectors give enough functionality for many cases.
If, for example, you want tables, to react to clicks on it’s rows, then you
can do this:
jQuery('table').listen( 'click', 'tr', function(){ alert('you clicked a row!!'); });
No matter how many times you add/remove rows, they will still be clickable.
You can also do this:
jQuery.listen( 'click', 'tr', function(){ alert('you clicked a row!!'); });
This time, the listener will be the document. So Now you can add/remove tables
as well, clicking the rows will still trigger the handler.
If you need full support for selectors, and you mind sacrificing a little of
scalability, you can check http://plugins.jquery.com/project/Intercept for a
similar solution.
jQuery Listen 官网
http://plugins.jquery.com/project/Listen
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。