H5/纯JS实现:把网页中的文字复制到剪切板

   const dom = document.getElementById(`span1`)
    const selection = window.getSelection()
    const range = document.createRange()

    // 选择复制目标
    range.selectNodeContents(dom)
    selection.removeAllRanges()
    selection.addRange(range)

    // 已复制文字
    console.log(‘selectedText‘, selection.toString())

    // 执行复制
    document.execCommand(‘copy‘)

    // 去除所有选中,否则该元素会显示为 被选中的颜色
    selection.removeAllRanges()