var p=1; active_list(); function active_list() { $.ajax({ type: "GET", url: "{:U('User/glodLogList_data')}", data: {page:p}, dataType: "json", success: function(data){ if(data==null){ $("#add_more").html('没有更多了'); $("#add_more").removeAttr("onclick"); }else{ var str = ''; for(i in data){ str += '<tr>'; str += '<td>'+data[i]['gtime']+'</td>'; if(data[i]['glod']>0){ str += '<td class="add">'+data[i]['glod']+'</td>'; }else{ str += '<td class="less">'+data[i]['glod']+'</td>'; } str += '<td>'+data[i]['glod_info']+'</td>'; str += '</tr>'; } $("#table").append(str); p++; $("#add_more").html('加 载 更 多...'); $("#add_more").attr("onclick","active_list()"); } } }); } $(window).scroll(function(){ var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).height(); var windowHeight = $(this).height(); if(scrollTop + windowHeight == scrollHeight){ active_list(); } });
代码供自己备用参考