要注意的是记得要先引用element操作模块 ,否则是无法绑定的
格式:
$(document).on(事件,标识,function(){});
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
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://www.cnblogs.com/weilxiaolat/p/11474253.html