原生js实现点击复制功能
代码:
<input type="text"><button>复制</button><script>var input = document.getElementsByTagName('input')[0]var button = document.getElementsByTagName('button')[0]button.onclick = function(){ input.value = "hello world" input.select() document.execCommand("copy")}</script>
效果:
execCommand常用方法:
cutdeletecopy
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。