thinkphp jq 实现列表查看更多功能

效果图


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;">&nbsp; &nbsp;'.$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('后面没有数据了');
    }
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值