用js实现一键复制微信号功能,百度推广专用

html代码:

<div>
    <span id="copyMy"> 复制我试试</span>
	<button onClick="copyFn()">点击复制</button>
</div>

 js代码:

    <script>
    	function copyFn() {
    		var val = document.getElementById('copyMy');
    		window.getSelection().selectAllChildren(val);
    		document.execCommand("Copy");
    		alert("已复制好,可贴粘。");
     
    	}
    </script>

 

posted @ 2020-06-22 23:58  IT驿站  阅读(1995)  评论(0编辑  收藏  举报