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

时间:2024-03-01 12:55:25

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>