1.添加html片段,放置在任意位置
<textarea style="position: absolute;top: -999999px;" id="tempCopyArea"></textarea>
2.调用js方法,传入文本
function copy(text) {
try {
console.log(text);
var textarea = document.getElementById('tempCopyArea');
textarea.value = text;
textarea.select();
return document.execCommand("copy"); //执行复制
} catch (e) {
return false;
}
}