js 复制字符到剪切板

const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
};
点击执行此函数

来源:https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
原文地址:https://www.cnblogs.com/shaoyang0123/p/12799913.html