更新时间:2023-12-05 09:22:34
您可以将document.ready
中的所有内容封装到一个函数中,然后再次调用该函数以重新绑定
you could encapsulate everything in your document.ready
into a function and just call that function again to re-bind
或...
一种更好的方法是利用live()
和delegate()
jQuery方法,以便与这些选择器匹配的所有当前和将来元素也将绑定到这些事件.
a better approach would be to take advantage of the live()
and delegate()
jQuery methods so that all current and future elements matching those selectors will be bound to these events as well.
使用live()
的示例: http://api.jquery.com/live/
$('.clickme').live('click', function() {
//all elements that exist now and elements added later
//with this class have this click event attached
});
使用delegate()
的示例: http://api.jquery.com/delegate/
$("table").delegate("td", "hover", function(){
//all current and future td elements in all current tables
//have this hover event attached
});