jQuery click事件第二次不起作用 [英] jQuery click event doesn't work the second time
问题描述
我正在使用jQuery通过Codeigniter处理和处理Ajax分页.
I'm using jQuery to handle and process Ajax pagination with Codeigniter .
当我第一次加载页面时,Ajax可以工作,但是当页面加载并且我单击另一个页面链接时,它不起作用(它转到本机URL).
When I load the page for the first time the Ajax works but when the page loaded and I click in the an other page link it doesn't work (it goes to the native URL).
这是我的jQuery函数:
This is my jQuery function:
function pagination(){
$('.paginate').click(function(){
$('#loading').css('display','block');
var b = $(this).attr('href');
b = b.split('/');
b = 'http://'+'/'+b[2]+'/'+b[3]+'/indexAjax/'+b[5];
grabpagination(b);
return false;
});
}
function grabpagination(b){
$.ajax({
type:'POST',
url: b,
cache: false,
data: {},
success: function (data) {
$("#center").replaceWith("<div id='center'>"+data+"</div>");
$('#loading').css('display','none');
$('html, body').animate({scrollTop: '0px'}, 1100);
},
dataType: 'html'
});
}
和分页UL的HTML
and the HTML of the pagination UL
<ul id="pagination">
<li class="current">1</li>
<li><a class="paginate" href="http://under.dev/home/index/2">2</a></li>
<li><a class="paginate" href="http://under.dev/home/index/4">3</a></li>
<li class="text"><a class="paginate" href="http://under.dev/home/index/2">التالي</a></li>
<li class="text"><a class="paginate" href="http://under.dev/home/index/14">الأخير</a></li>
</ul>
under.dev
只是一个虚拟域.
怎么了?我正在使用Firebug进行调试,但没有给出任何错误.
What's wrong? I'm using Firebug for debugging but it doesn't give any error.
使用Live()
函数解决.
SOLVED Using Live()
function.
推荐答案
如果要绑定到动态加载的数据,则需要使用live()函数绑定事件.
You need to bind events with the live() function if you want to bind to dynamically loaded data.
这篇关于jQuery click事件第二次不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!