$("#copy-btn-text").unbind("click").on("click", function (event) {
MtaH5.clickStat('qtk_newdetail', {'copy': 'true'})
var event = event || window.event;
event.preventDefault();
var initClipboard = new ClipboardJS('#copy-btn-text');
var html, txt, imgSrc, tbCopyImgUrl;
txt = $(".media-text-area").text();
txt = txt.replace(/\s+/ig, "<br/>");
imgSrc = "<?= \app\utils\Utils::getNewCopyPic(\app\utils\Utils::getQqPic($goods_info)); ?>";
html = "<img src='" + imgSrc + "'><br/>" + txt + "";
if (document.getElementById('copyInput')) {
//存在复制内容框重置值
$('#copyInput').html(html);
} else {
//不存在复制内容框设置
var copy = document.createElement('div');
copy.id = "copyInput";
copy.innerHTML = html;
copy.style = "opacity:0;position:absolute;top:0;z-index:-2;";
document.body.appendChild(copy);
}
var copy = document.getElementById('copyInput');
initClipboard.target = function () {
return copy
}
initClipboard.on('success', function (e) {
layer.msg('已复制', {
time: 2000
}
);
e.clearSelection();
initClipboard.destroy();
});
initClipboard.on('error', function (e) {
console.log("error")
layer.msg('复制失败,请升级或更换浏览器后重新复制!', {
time: 2000
}
);
e.clearSelection();
initClipboard.destroy();
});
});
var clipboard = new ClipboardJS('.wenan', {
'target': function (trigger) {
return document.querySelector(".layui-layer-content");
}
});
clipboard.on('success', function (e) {
layer.msg("已复制", {
time: 1500
});
e.clearSelection();
});
clipboard.on('error', function (e) {
layer.msg("由于您的浏览器不兼容或当前网速较慢,复制失败,请手动复制或更换主流浏览器!", {
icon: 2
})
});
文案复制的代码
于 2019-09-03 21:01:44 首次发布