原生js+h5实现复制文本到剪贴板;pc+wap通用
HTML
<input type="text" id="input" value="17373383"> <br> <button type="button" id="button">复制输入框中内容</button>
JAVASCRIPT
button.addEventListener('click', function(){ var inputs = document.getElementById("input") inputs.select(); alert(document.execCommand('copy')); })
本质就是模拟选择所要复制的文本,再调用命令进行复制,这样就无需考虑浏览器兼容等问题
QQ群:513185891