// 单个复制
<div id=“fuzhi">复制</div>
<p id="copyBT”>复制内容</p>
function copyArticle1(event) {
const range = document.createRange();
// 复制元素
range.selectNode(document.getElementById('copyBT'));
const selection = window.getSelection();
if (selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
mui.toast("复制成功!");
}
document.getElementById('fuzhi').addEventListener('click', copyArticle1, false);
// 多个复制 把需要复制的文字给按钮
$(document).on("click", ".fuzhi", function() {
$("#copyBT2").html("");
// data_con 复制内容
var data = $(this).attr("data_con");
$("#copyBT2").html(data);
copyArticle();
})
function copyArticle(event) {
const range = document.createRange();
// 复制元素
range.selectNode(document.getElementById('copyBT2'));
const selection = window.getSelection();
if (selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
console.log("复制成功!");
}
<div id = "copyBT2" style = "opacity: 0;" > </div>
js 复制
最新推荐文章于 2024-08-16 15:55:37 发布