您的位置:首页 > 产品设计 > UI/UE

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

2019-09-06 09:52 1096 查看

要注意的是记得要先引用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');

});
});

以上这篇在layui下对元素进行事件绑定的实例就是小编分享给大家的全部内容了,希望能给大家一个参考

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  layui 元素 事件绑定