common.js 679 B

123456789101112131415161718192021
  1. var copyNO = document.getElementById("copyNO");
  2. function h5Copy() {
  3. if (!document.queryCommandSupported('copy')) {
  4. // 不支持
  5. alert("不支持复制")
  6. return;
  7. }
  8. var content = copyNO.getAttribute("data-value");
  9. let textarea = document.createElement("textarea")
  10. textarea.value = content
  11. textarea.readOnly = "readOnly"
  12. document.body.appendChild(textarea)
  13. textarea.select() // 选择对象
  14. textarea.setSelectionRange(0, content.length) //核心
  15. let result = document.execCommand("copy") // 执行浏览器复制命令
  16. textarea.remove()
  17. alert('复制【' + content + '】成功');
  18. }
  19. copyNO.onclick = h5Copy;