const copyToClipboard = async (text) => { if (navigator.clipboard && navigator.permissions) { await navigator.clipboard.writeText(text) } else { const textareaEl = document.createElement('textarea') textareaEl.setAttribute('readonly', 'readonly') // 防止手機上彈出軟鍵盤 textareaEl.value = text document.body.appendChild(textareaEl) textareaEl.select() const res = document.execCommand('copy') document.body.removeChild(textareaEl) } console.log('復(fù)制成功') }
|