点击复制文本
點擊按鈕,進行文本復制操作。實現這個功能需要二點;
?一:用window.getSelection().selectAllChildren(“”)獲取要復制的內容?
?二:用document.execCommand ("Copy");進行復制操作
關鍵代碼
window.getSelection().selectAllChildren(val);document.execCommand ("Copy");?
HTML
<p id="copyWeChat">要復制的內容</p><span οnclick="copyFn('copyWeChat')">復制</span>
?
JS
<script>function copyFn(id){var val = document.getElementById(id);window.getSelection().selectAllChildren(val);document.execCommand ("Copy");alert("復制成功")}</script>?
轉載于:https://www.cnblogs.com/zimengxiyu/p/9954856.html
總結
- 上一篇: DAY77-Django框架(八)
- 下一篇: ZOJ1081 Points Withi