网络编程
位置:首页>> 网络编程>> JavaScript>> 在layui下对元素进行事件绑定的实例

在layui下对元素进行事件绑定的实例

作者:Q-u-a-n  发布时间:2024-04-22 22:17:27 

标签:layui,元素,事件绑定

要注意的是记得要先引用element操作模块 ,否则是无法绑定的

格式:

$(document).on(事件,标识,function(){});


layui.use(['jquery', 'form', 'table', 'element'], function() {
 var form = layui.form;
 var table = layui.table;
 var element = layui.element;
 var $ = layui.$;

// form.render();
 table.render({
  elem: '#tableList',
  // height: 315,
  url: "{{route('admin.data')}}",
  page: true, //开启分页
  cols: [
   [ //表头
    { field: 'id', title: 'ID', sort: true, fixed: 'left' },
    { field: 'name', title: '用户名' },
    { field: 'role', title: '角色', sort: true },
    {
     field: 'status',
     title: '状态',
     templet: function(d) {
      return d.status == 0 ? '禁止' : '启用'
     }
    },
    { field: 'created_at', title: '创建时间' },
    {
     title: '操作',
     // minWidth: 200,
     templet: function(d) {
      return '<button class="layui-btn layui-btn-xs " lay-filter="editF" id="edit" data-id="' + d.id + '">编辑</button>'
     }
    }
   ]
  ]
 });
 //绑定事件
 $(document).on('click', '#edit', function(data) {
  var id = $(this).attr('data-id');

});
 });

来源:https://blog.csdn.net/sqlquan/article/details/81915348

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com