文章加载更多

<script src="JS/jquery.min.js"></script>    

<a href="javascript:;" class="btn" >加載更多</a>
</body>
<script type="text/javascript">
var nStart = 10;

$('.btn').click(function() {
var _this = $(this);
if(nStart >= {$total}) {
alert('后面没有数据了!');
_this.text('后面没有数据了');
return false;
} else {
$.post("{:U('articleAjax')}", {start: nStart}, function(res) {
$.each(res['result'], function(i, item) {
var id= item.id;
var type= item.type;
var title= item.title;
var time= item.time;
var timeStr = time; //时间戳你自已取的值
var tim = new Date(parseInt(timeStr) * 1000); //如果时间戳是后端生成 要 * 1000
var year = tim.getFullYear(); //年
var month = tim.getMonth() + 1; //月
month = month < 10 ? '0' + month : month;
var day = tim.getDate();//日
day = day < 10 ? '0' + day : day;
var newtime = month + '/' + day;
if(type ==1) {
var url = "{:U('Mobile/MobileNewsInfo/mobileNewsInfo')}";
url += '?id='+id;
_this.before('<ul class="list">\
<li>\
<a href='+ url +'>\
<span>新聞</span>\
<p>' + title + '</p>\
<time>' + newtime + '</time>\
<div class="clear"></div>\
</a>\
</li>\
</ul>');
}
if(type ==3) {
var url = "{:U('Mobile/MobileActInfo/mobileActInfo')}";
url += '?id='+id;
_this.before('<ul class="list">\
<li>\
<a href='+ url +'>\
<span>活動</span>\
<p>' + title + '</p>\
<time>' + newtime + '</time>\
<div class="clear"></div>\
</a>\
</li>\
</ul>');
}
if(type ==2) {
var url = "{:U('Mobile/MobileStrategyInfo/mobileStrategyInfo')}";
url += '?id='+id;
_this.before('<ul class="list">\
<li>\
<a href='+ url +'>\
<span>攻略</span>\
<p>' + title + '</p>\
<time>' + newtime + '</time>\
<div class="clear"></div>\
</a>\
</li>\
</ul>');
}
if(type ==4) {
var url = "{:U('Mobile/MobileTipInfo/mobileTipInfo')}";
url += '?id='+id;
_this.before('<ul class="list">\
<li>\
<a href='+ url +'>\
<span>公告</span>\
<p>' + title + '</p>\
<time>' + newtime + '</time>\
<div class="clear"></div>\
</a>\
</li>\
</ul>');
}

});
});
nStart += 10;
}
});
</script>


php 页面

<?php
namespace Mobile\Controller;
use Think\Controller;
class MobileListController extends Controller {
public function MobileList(){
$content = M("wapcontent");
$total = $content->count();
$this->assign('total', $total);
$data=$content->limit(10)->order('id DESC')->select();
$this->assign('data',$data);
$this->display();
}
public function articleAjax() {
$content = M("wapcontent");
$start = I('post.start');
$list = $content->limit($start,10)->order('id DESC')->select();
$this->ajaxReturn(array( 'result'=>$list,'status'=>1, 'msg'=>'获取成功!'));
}

}




附件列表

     

    posted @ 2017-05-05 10:59  大咸菜·  阅读(211)  评论(0编辑  收藏  举报