table.js 找到单元格缩放后,下拉展示内容 layui-table-grid-down
鼠标放上单元格时,显示复制按钮
a.layBody.on("click", "td", function (e) {
...
}
}).on("mouseenter", "td", function () {
b.call(this)
// 调用 ly 方法
ly.call(this)
}).on("mouseleave", "td", function () {
b.call(this, "hide")
// 隐藏
ly.call(this, "hide")
});
var copy = "layui-table-list-copy",ly = function (e) {
var i = t(this), a = i.children(f);
if (e) i.find(".layui-table-list-copy").remove();
else if (i.attr('lay-event') === "PrimaryId" && a.prop("scrollWidth") === a.outerWidth()) {
if (a.find("." + copy)[0]) return;
// 插入icon,input框方便待会选中内容.
i.append('<div class="' + copy + '"><i class="layui-icon layui-icon-file-b"></i><input class="table-copy-text" style="display: none;" value="'+$(a).text()+'"></div>')
}
}
a.layBody.on("click","."+copy,function(e) {
var i = t(this), n = i.parent(), d = n.children(f), copyText = $('.table-copy-text');
// 显示 input
copyText.show();
d.contentEditable = true;
// 选择 input 内容
copyText.select();
try{
// 利用 document.execCommand 进行复制操作
if(document.execCommand("Copy","false",null)){
layer.msg('复制成功');
}else{
layer.msg("复制失败!请手动复制!");
}
}catch(err){
layer.msg("复制错误!请手动复制!")
}
copyText.hide();
layui.stope(e)
});
var g = "layui-table-grid-down", b = function (e) {
...
};
记得样式加上 全局搜索 layui-table-grid-down 样式有的都给 layui-table-list-copy 加上