zoukankan      html  css  js  c++  java
  • Thinkphp 加载更多

    要实现的效果是这样的:


    每次点击显示更多按钮,都会往下显示2条数据,直到后面没有数据了。。

    数据表:


     

    articleList模板文件

    <include file="./Application/Common/View/Public/header.html" />
    <div class="container">
    <volist name="list" id="vo">
    <div class="panel panel-default">
    <div class="panel-heading">{$vo.title}</div>
    <div class="panel-body">{$vo.content}</div>
    </div> </volist>
    <if condition="count($list) eq 5">
    <a class="btn btn-block btn-default" style="margin-bottom: 20px;" href="javascript:;">显示更多</a>
    </if>
    </div>
    <script>
    var nStart = 5;
    $('.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) { _this.before('<div class="panel panel-default"> <div class="panel-heading">'+item.title+'</div> <div class="panel-body">'+item.content+'</div> </div>'); }); }); nStart += 2; } });
    </script> <include file="./Application/Common/View/Public/footer.html" />

    Index控制器中的articleList方法和articleAjax返回方法

    // 文章列表
    public function articleList() { $article = M('article'); $total = $article->count(); $this->assign('total', $total); $list = $article->limit(5)->order('id asc')->select(); $this->assign('list', $list); $this->display(); } // ajax异步加载文章
    public function articleAjax() { $article = M('article'); $start = I('post.start'); $list = $article->limit($start, 2)->order('id asc')->select(); $this->ajaxReturn(array( 'result'=>$list,'status'=>1, 'msg'=>'获取成功!')); }

    https://blog.csdn.net/u010081689/article/details/46702507?utm_source=blogxgwz10

  • 相关阅读:
    交互设计必懂--开发有价值的用户体验
    优秀APP启动页的设计思维
    增加用户体验的细节--三个按钮的交互设计思维
    零基础掌握交互设计的重点笔记
    在失败的滴滴出行LOGO上谈APP设计
    是成为设计的主人?还是沦为设计的工具?
    大图标+不规则几何创造不同风格
    如何定义视觉设计规范?
    10条SKETCH的秘诀,为你提高工作的效率
    MVC过滤器详解
  • 原文地址:https://www.cnblogs.com/lxwphp/p/9854503.html
Copyright © 2011-2022 走看看