{
                            field: 'url', title: __('Url'), operate: false, formatter: function (value, row, index) {
                                return "/pages/ask/form?id="+row.id+" | <a class='copy' href='javascript:' data-copy='/pages/ask/form?id="+row.id+"' >复制</a>";
                            }

                        },


// Table.api.bindevent(table);上面
function copyToClipboard(text) {
              // 创建一个临时的 textarea 元素
              const textarea = document.createElement('textarea');
              // 将 textarea 设为可编辑,以便复制
              textarea.setAttribute('readonly', '');
              textarea.style.position = 'absolute';
              textarea.style.left = '-9999px';
              // 将目标文本设置到 textarea 中
              textarea.value = text;
              document.body.appendChild(textarea);
              // 选中 textarea 中的文本
              textarea.select();
              textarea.setSelectionRange(0, textarea.value.length);
              // 复制文本
              const success = document.execCommand('copy');
              // 从文档中移除 textarea
              document.body.removeChild(textarea);
              // 返回复制操作是否成功
              return success;
            }

            function copy(text) {
               if (copyToClipboard(text)) {
                  Layer.msg('复制成功!');
                } else {
                  Layer.msg('复制失败!');
                }
            }

            $(document).on("click", ".copy", function () {
                var txt=$(this).data("copy");
                copy(txt);
            })

点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部