//$qrname 为要复制的内容
<div class="page-right" id="user" onclick="copy('要复制的内容')" >推广链接</div>
js代码
function copy(message) {
var input = document.createElement("input");
input.value = message;
document.body.appendChild(input);
input.select();
input.setSelectionRange(0, input.value.length), document.execCommand('Copy');
document.body.removeChild(input);
alert("复制成功", "text");
}
本文介绍了一种使用JavaScript实现的网页一键复制功能,通过创建并操作DOM元素完成文本的复制,适用于网页推广链接等场景。
1051

被折叠的 条评论
为什么被折叠?



