實現復制dom節點中的內容:
function copyText (ele) { try { let selection = window.getSelection() if (selection.rangeCount > 0) selection.removeAllRanges() let range = document.createRange() range.selectNodeContents(ele) selection.addRange(range) document.execCommand("copy") selection.removeAllRanges() return Promise.resolve({success: true, message: '復制成功'}) } catch (error) { return Promise.resolve({success: false, message: '復制失敗'}) } }