点击按钮复制某内容

<p id="copy" style="background-image:none;">
                <img src="images/TiaoDong.png">
        </p>
                <script>
                        function copyArticle(event) {
                                const range = document.createRange();
                                range.selectNode(document.getElementById('cod'));
                                const selection = window.getSelection();
                                if(selection.rangeCount > 0) selection.removeAllRanges();
                                selection.addRange(range);
                                document.execCommand('copy');
                                alert("复制微信号成功,请前往微信添加好友!")
                        }
                        document.getElementById('copy').addEventListener('click', copyArticle, false);
                </script>
原文地址:https://www.cnblogs.com/zyl-930826/p/8649373.html