function copy() { let transfer = document.createElement(‘input‘); document.body.appendChild(transfer); transfer.value = ‘这里是想要复制的内容‘; transfer.focus(); transfer.select(); if (document.execCommand(‘copy‘)) { document.execCommand(‘copy‘); } transfer.blur(); console.log(‘复制成功‘); document.body.removeChild(transfer); }