實現方式
function copyTable() {
const table = document.getElementById('table')
const range = document.createRange()
// 設定range包含的節點對象
range.selectNode(table)
// 窗口的selection對象,表示用戶選擇的文本
const selection = window.getSelection()
// 將已經包含的已選擇的對象清除掉
if (selection.rangeCount > 0) selection.removeAllRanges()
// 將要複製的區域的range對象添加到selection對象中
selection.addRange(range)
// 執行copy命令,copy用戶選擇的文本
document.execCommand('copy')
}