Jquery点击功能触发加载更多按钮

时间:2013-01-15 07:56:14

标签: javascript jquery

下面我有3个链接作为标签:

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

<li data-tab-id="friends" class="tab"><a href="#">Following</a><span class="unread-count hidden" style="display: none;"></span></li>

<li data-tab-id="user" class="tab"><a href="#">Your Activity</a><span class="unread-count hidden" style="display: none;"></span></li>

当我点击上面的链接Jquery点击功能被触发

$(".hd-ui-activity li a").click(function(e) {
e.preventDefault();
var tabid = $(this).parent().attr('data-tab-id');
    if(tabid == "self"){
            getFunc1(totalRecords);
        } else if(tabid == "friends") {
            getFunc2(totalFriendsRecords);
        } else if(tabid == "user") {
            getFunc3(totalUserRecords);
        }
});

当点击每个链接/标签时,调用函数getFunc1(),将html附加到下一个div(每个func都有自己的div)

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

div上只显示4个列表结果,当用户单击see more activity按钮时,会将更多结果加载到div中。现在的问题是当页面加载它正确显示4结果但当我再次点击链接而不是按钮时所有数据都显示出来。我很难在标签之间导航。我怎么能避免这个?

更新

var totalFriendsRecords = '<?=$this->followingTotal?>';
function getRecentActivityFriends(event)
{
    if (event != null){
            disabledEventPreventDefault(event);
        }
        getFriendsActivity(totalFriendsRecords);
}

home.js

var totalFriendsRecordsView = 0;
function getFriendsActivity(totalFriendsRecords)
{
var activityHtml =  ''
$.ajax({
        url:baseUrl + "activity/feedfollowing",
        data:{'total':totalFriendsRecordsView},
        dataType:"json",
        type:"POST",
        success:function(data){

for(var i=0; i<data.length; i++){
activityHtml = '<p>'+data[i][name]+'</p>';
}
$('#activity-feed li[data-section-id=following] .module-list').append(activityHtml);
if( totalFriendsRecords <=  totalFriendsRecordsView){

                $('.following').text('Nothing beyond here ...');
                $('.following').removeAttr('onclick');
                $('.following').removeAttr('href');
            }

}
});
}

0 个答案:

没有答案