详情小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
493 B

  1. export default function h5Copy(content) {
  2. if (!document.queryCommandSupported('copy')) {
  3. // 不支持
  4. return false
  5. }
  6. let textarea = document.createElement("textarea")
  7. textarea.value = content
  8. textarea.readOnly = "readOnly"
  9. document.body.appendChild(textarea)
  10. textarea.select() // 选择对象
  11. textarea.setSelectionRange(0, content.length) //核心
  12. let result = document.execCommand("copy") // 执行浏览器复制命令
  13. textarea.remove()
  14. return result
  15. }