function copy() { const range = document.createRange(); range.selectNode(document.getElementById('wxNumber'));//需要复制的内容 const selection = window.getSelection(); if(selection.rangeCount > 0) selection.removeAllRanges(); selection.addRange(range); document.execCommand('copy'); alert("复制成功!打开微信添加好友"); }