【问题标题】:Jquery tabs with load more button带有加载更多按钮的 Jquery 选项卡
【发布时间】:2014-08-02 20:45:13
【问题描述】:

您好,是否有任何关于在每个选项卡中加载更多功能的 php ajax 选项卡的参考/示例?假设我们有 2 个选项卡,当我们单击每个选项卡时,它将仅显示选定数量的结果,直到我们单击每个结果末尾的加载更多按钮。谢谢。我当前的代码似乎效果不佳,当我单击每个选项卡时,它会正确显示结果,但是当我再次单击选项卡时,它会加载更多数据。以下是我当前的代码:

<li data-tab-id="self" class="tab selected"><a href="#">Near You</a><span class="unread-count hidden" style="display: none;"></span></li>


<li data-section-id="user_feed" data-component-bound="true">
    <ul class="module-list">                            
    <!-- USER ACTIVITY JSON -->
    </ul>
    <a class="ybtn ybtn-primary ybtn-large more-wishlist" href="#" onclick="getRecentActivityClick(event)">
    <span data-component-bound="true" class="loading-msg user_feed">See more recent activity</span>
    </a>
</li>

<script type="text/javascript">
var totalRecords = '<?= $this->totalRecords?>';
$(document).ready(function(){
getRecentActivity(totalRecords);
});

$(".hd-ui-activity li a").click(function(e) {
e.preventDefault();
var tabid = $(this).parent().attr('data-tab-id');
if(tabid == "self"){
        getRecentActivity(totalRecords);

    }
});

function getRecentActivityClick(event)
{
    if (event != null){
            disabledEventPreventDefault(event);
        }
        getRecentActivity(totalRecords);
}

home.js:

function getRecentActivity(totalRecords)
{
$.ajax({
        url:baseUrl + "activity/activityfeed",
        data:{'total':totalRecordsView},
        dataType:"json",
        type:"POST",
        success:function(data){

 var activityHtml = '<p>Hello</p>';
$('#activity-feed li[data-section-id=near_you] .module-list').append(activityHtml);


}
});

}

更新: JSFIDDLE:http://jsfiddle.net/zlippr/5YkWw/1/

【问题讨论】:

    标签: php javascript jquery ajax


    【解决方案1】:

    我从你的问题中了解到.. 我认为你正在获得更多数据,因为你正在使用.. append().. 使用html()

    append() 将参数指定的内容插入到匹配元素集中每个元素的末尾。

    html() 用于设置元素的内容,该元素中的任何内容都会被新内容完全替换。

    试试这个

    替换

    $('#activity-feed li[data-section-id=near_you] .module-list').append(activityHtml);
    

    $('#activity-feed li[data-section-id=near_you] .module-list').html(activityHtml); //html()
    

    【讨论】:

    • 当我点击它仍然加载新数据的标签时仍然没有解决,它不应该加载数据,直到用户点击底部的加载更多按钮..
    • 不清楚你想要得到什么......你正在加载$(document).ready(function(){...中的内容......这就是为什么你在点击之前获取数据......你可以为此创建小提琴吗??
    • 你的查看更多按钮在哪里...我找不到它...这是我更新的小提琴...jsfiddle.net/5YkWw/2
    【解决方案2】:

    你可以这样做:

     $('#activity-feed li[data-section-id=near_you] .module-list').append(activityHtml);
     // here you are appending the fulldata just apply some css here
    

    以这种方式使用 css:

    $('#activity-feed li[data-section-id=near_you] .module-list')
        .css({'height':'300px','overflow':'hidden'})
        .append(activityHtml);
    

    然后点击加载更多:

    $('your load more button').toggle(function(){
       $('#activity-feed li[data-section-id=near_you] .module-list')
        .css({'height':'auto','overflow':'auto'})
        },function(){
       $('#activity-feed li[data-section-id=near_you] .module-list')
        .css({'height':'300px','overflow':'hidden'});
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-28
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 2011-10-23
      • 2012-02-16
      • 1970-01-01
      相关资源
      最近更新 更多