我敢肯定这是一件AJAX大师们学得很早,但是这是我第一次碰到这个问题。使用jQuery,我已经分配。点击()处理程序与特定CSS类。不过,如果我重新加载一些通过AJAX的。点击的内容()处理程序不触发该内容。
I'm sure this is something that AJAX gurus learn very early on, but this is the first time I've run into it. Using jQuery, I have assigned .click() handlers to certain CSS classes. However, if I reload some of the content via AJAX, the .click() handlers are not firing for that content.
看来我有两个选择:
在把我的。点击()处理程序分配一个JScript函数中,并调用它每一次的内容是通过AJAX刷新。 使用的onclick =,而不是我的jQuery的AJAX内容中。迄今为止,似乎#1将是最好的;这是比较一致的,并产生更小的HTML AJAX。
So far, it seems #1 would be the best; it's more consistent and yields smaller HTML for AJAX.
有另一种方式做到这一点?分配。点击()处理程序从一开始或许是一种不同的方式?
Is there another way to do it? Perhaps a different way of assigning the .click() handlers from the outset?
您正在寻找 生活()
的方法来代替。
You are looking for the live()
method instead.
$('selector').live('click', function(){
// your code.......
});
在生活
现在或将来的作品元素present。
The live
works for elements present now or in the future.