Blogger Information
Blog 9
fans 0
comment 0
visits 5003
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
6月7作业(layui处理分页)
张凯的博客
Original
538 people have browsed it
controller index.php

<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        $curr = max(1,(int)input('get.page'));
        $this->view->assign('data',$curr);
        return $this->view->fetch();
    }
}

view index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>hello</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/layui/layui.js"></script>
</head>
<body>
    <form action=""> 
         <div>
            <label>选择框</label>
            <div>
              <select name="interest" lay-filter="aihao">
                <option value=""></option>
                <option value="0">写作</option>
                <option value="1">阅读</option>
                <option value="2">游戏</option>
                <option value="3">音乐</option>
                <option value="4">旅行</option>
              </select>
            </div>
          </div>
    </form>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
      <legend>自定义排版</legend>
    </fieldset>
     ======
     {$data}
     ====
    <div id="demo8"></div>
</body>
</html>
<script>
layui.use(['form','laypage','layer'],function(){
    var form = layui.form;
    var laypage = layui.laypage;
    var layer = layui.layer;
    //自定义排版
    laypage.render({
        elem: 'demo8'
        ,count: 100
        ,curr: {$data}
        ,layout: ['limit', 'prev', 'page', 'next']
        ,jump: function(obj, first){
        //obj包含了当前分页的所有参数,比如:
        // console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
        // console.log(obj.limit); //得到每页显示的条数
        
        //首次不执行
        if(!first){
            console.log(obj.curr);
            window.location.href = '?page='+obj.curr;
          //do something
        }
      }
    });
})
</script>


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post