var temp = document.createElement('input');temp.value="xx";document.body.appendChild(temp);temp.select();if(document.execCommand('copy')){document.execCommand('copy');document.body.removeChild(temp);window.alert("复制成功");}else{window.alert("复制失败");}
参考:前端 Tips#7 - 用 6 行代码实现文本复制