效果图
php
<?php namespace Home\Controller; class NewsController extends HomeController{ public function answerlist(){ $page = I('post.page',1); $where['type'] = '问题答疑'; $this->page($where,$page); } public function course(){ $page = I('post.page',1); $where['type'] = '新手教程'; $this->page($where,$page); } public function page($where,$page){ $new = D('News'); $ordernum =$new->where($where)->count(); $res = $new->where($where)->order('time desc')->page($page.',10')->select(); $reshtml=''; foreach($res as $key =>$value){ $reshtml .= ' <li> <div class="b_news_list"> <img src="http://hy.exinl.com/public/static/goo/wyc/srwyc/news7.png" class="b_news7"> <div class="b_news_list_right flip2"> <span class="b_ct"> <b>'.$value['title'].'</b> <em>'.$value['time'].'</em> </span> <img src="http://hy.exinl.com/public/static/goo/wyc/srwyc/news1.png" id="flip_'.$value['id'].'" class="b_new1" > </div> <div class="b_news_con panel" style="display: none; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238);"> <p style="color: #333;">亲爱的无忧家人:<br></p> <pre style="white-space: pre-wrap;word-wrap: break-word; border: none;"> <p style="color: #333;"> '.$value['content'].'</p> </pre> </div> </div> </li>'; } if($page == 1){ $this->assign('ordernum',$ordernum); $this->assign('page',$page); $this->assign('res',$res); $this->display(); }else{ $res['result'] = $reshtml; $res['status'] = 1; $res['nodata'] = max(0,($ordernum - ($page * 10))); $this->ajaxReturn($res); } } public function index(){ $this->display(); } } ?>
jq代码
var nStart = 2; $('.btn').click(function() { $.post("{:U('Home/News/answerlist')}", {page: nStart}, function(res) { $("#b_news_ul").append(res['result']); }); nStart +=1; if(nStart>=Math.ceil('{$ordernum}'/10)){ var _this = $(this); _this.text('后面没有数据了'); } });