layui 点击链接复制内容到剪切板

var tableObj = table.render({
            id: 'list_table',
            elem: '#list_table',
            url: '',
            align: "center",
            cols: [[ //表头
                {type: 'checkbox'},
                {type: 'numbers', title: '序号',width:80},
                {
                    field: 'lock', title: '链接', align: 'center', templet: function (d) {
                    return   '分享';
                }, unresize: true, align: 'center'
                }
            ]]
        });
 table.on('tool(mainList)', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
		if (layEvent === 'share') {
	              $(".font-primary").attr("data-clipboard-text",data.id);
	              var clipboard = new ClipboardJS('.font-primary');
	              clipboard.on('success', function(e) {
	                  alert('复制成功');
	                  clipboard.destroy();  //解决多次弹窗
	                  e.clearSelection();
	              });
		 }
	})

你可能感兴趣的:(layui 点击链接复制内容到剪切板)