【layUI】:项目搭建|+分页器demo+弹窗的使用注意事项+layui与jquery结合使用

一、下载layui文件包,部署到项目目录

https://www.layui.com/

在html中引入其中两个文件。

二、以分页器为例

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="layui/css/layui.css">
  <style>
    #biuuu_city_list {
      width: 400px;
      height: auto;
      background-color: aquamarine;
      box-sizing: border-box;
      padding: 10px 30px;
    }
  </style>
</head>
<body>
   
  <div id="demo20"></div>
  <ul id="biuuu_city_list"></ul> 

  <script src="layui/layui.js"></script>
  <script>
    layui.use('laypage', function(){
      var laypage = layui.laypage
     
      //测试数据
      var data = [
        '北京',
        '上海',
        '广州',
        '深圳',
        '杭州',
        '长沙',
        '合肥',
        '宁夏',
        '成都',
        '西安',
        '南昌',
        '上饶',
        '沈阳',
        '济南',
        '厦门',
        '福州',
        '九江',
        '宜春',
        '赣州',
        '宁波',
        '绍兴',
        '无锡',
        '苏州',
        '徐州',
        '东莞',
        '佛山',
        '中山',
        '成都',
        '武汉',
        '青岛',
        '天津',
        '重庆',
        '南京',
        '九江',
        '香港',
        '澳门',
        '台北'
      ];
      
      //调用分页
      laypage.render({
        elem: 'demo20'
        ,count: data.length
        ,jump: function(obj){
          //模拟渲染
          document.getElementById('biuuu_city_list').innerHTML = function(){
            var arr = []
            ,thisData = data.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
            layui.each(thisData, function(index, item){
              arr.push('<li>'+ item +'</li>');
            });
            return arr.join('');
          }();
        }
      });
    });
   
  </script>

</body>
</html>

效果:

三、在项目中使用弹窗的时候,弹窗模块有单独的样式文件,处理引入以上的css文件外,还要引入layer.css。否则不生效

四、项目中用jquery处理页面逻辑,(layui官网有示例)

//使用拓展模块
layui.use(['jquery', 'cookie'], function(){
  var $= layui.jquery
  ,cookie= layui.cookie;
});

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个使用layui+Python+Flask+MySQL实现的分页代码示例: HTML代码: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>分页示例</title> <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.5.6/css/layui.min.css"> </head> <body> <div class="layui-container"> <table class="layui-table"> <thead> <tr> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>地址</th> </tr> </thead> <tbody id="table_data"></tbody> </table> <div id="page"></div> </div> <script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/layui/2.5.6/layui.min.js"></script> <script> layui.use(['laypage', 'layer'], function(){ var laypage = layui.laypage, layer = layui.layer; laypage.render({ elem: 'page', limit: 10, curr: 1, count: 100, jump: function(obj, first){ if(!first){ $.ajax({ url: '/get_data', type: 'POST', dataType: 'json', data: { page: obj.curr, limit: obj.limit }, success: function(data){ if(data.code == 0){ var html = ''; for(var i=0;i<data.data.length;i++){ html += '<tr>'; html += '<td>'+data.data[i].name+'</td>'; html += '<td>'+data.data[i].age+'</td>'; html += '<td>'+data.data[i].gender+'</td>'; html += '<td>'+data.data[i].address+'</td>'; html += '</tr>'; } $('#table_data').html(html); } else{ layer.msg('获取数据失败!'); } }, error: function(){ layer.msg('获取数据失败!'); } }); } } }); }); </script> </body> </html> ``` Python代码: ```python from flask import Flask, render_template, request, jsonify import pymysql app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/get_data', methods=['POST']) def get_data(): page = request.form.get('page', 1, type=int) limit = request.form.get('limit', 10, type=int) offset = (page - 1) * limit conn = pymysql.connect(host='localhost', user='root', password='123456', database='test', charset='utf8') cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute('SELECT * FROM users LIMIT %s, %s', (offset, limit)) data = cursor.fetchall() cursor.execute('SELECT COUNT(*) FROM users') count = cursor.fetchone()['COUNT(*)'] cursor.close() conn.close() return jsonify({'code': 0, 'msg': '', 'data': data, 'count': count}) if __name__ == '__main__': app.run(debug=True) ``` 这个示例使用jQuerylayui库,通过ajax异步获取分页数据。在Python部分,使用了pymysql库连接MySQL数据库,通过分页查询获取数据并返回给前端。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值