[英]Jquery tabs with load more button
嗨,是否有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/
我从您的问题中了解的..我认为您正在获取更多数据,因为您正在使用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()
你可以这样做:
$('#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);
然后单击loadmore:
$('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'});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.