点击按钮复制某内容

 

<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>
posted @ 2018-03-26 10:39  风干记忆  阅读(264)  评论(0编辑  收藏  举报