JS, javascript,copy ,execCommand, js 复制 文本。
利用document的命令,用按钮复制文本。注意:execCommand即将废弃。以下是参考代码: const range =&nbs
利用document的命令,用按钮复制文本。
注意:execCommand即将废弃。
以下是参考代码:
const range = document.createRange(); range.selectNode(document.getElementById('you div id')!); const selection = window.getSelection(); if (selection!.rangeCount > 0) { selection?.removeAllRanges(); } selection?.addRange(range); document.execCommand('copy'); Toast.show('复制成功', 1); if (selection!.rangeCount > 0) { selection?.removeAllRanges(); }