English 中文(简体)
Jquery: 只需在第一个点击“ 加载更多... ” 时加载下一页 。
原标题:Jquery: only loads the next page on first click of "load more..."
  • 时间:2012-05-25 06:22:58
  •  标签:
  • jquery
  • ajax

如果 DIV, 我需要在每点击“ 加载更多” 文本的结尾处加载内容。 我目前的代码如下:

<div id="Container"> <p class="load">load more</P> </div>

$(".load:last").click(function(){
$(".load:last").load("nextPage.php", function() {
$(this).hide();

$("div#Container").append($(this).html());
$("div#Container").append("<p class="load">load more...</p>");

});

第一个点击工作, 因为它从下个Page.php 上载更多 。 但是随后的点击不会触发负载 。 我做错什么了?

最佳回答
    $(".load:last").live( click , function () {
        $(this).remove();
        //Or
        // $(this).hide();
        $(".load:last").load("nextPage.php", function () {
            $("div#Container").append($(this).html());
            $("div#Container").append("<p class="load">load more...</p>");
        });
    });
问题回答

.load 每次附加到 div# container 新的 < code> 时, 您应该使用活动实时处理器到那个 < code>. load , 如 :

$("div#Container").on( click ,  .load , function() {
  $(this).parent( div#Container ).load( nextPage.php , function() {
     $( div#Container ).append("<p class="load">load more...</p>");
  })
})

尝试使用 < strong>. live() 方法或jquery < / strong > 的.on() 。 此选项附加一个事件处理器, 用于匹配当前选择器的所有元素, 现在和将来 。

Click here for information and example for .live event in jquery
I hope this will definitely solve you problem.

最好运气!! :)





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签