This article mainly shares with you the js copy text content to the clipboard implementation code, I hope it can help everyone.
Compatible with mainstream browsers
<script type="text/javascript"> function copyUrl2() { var Url2=document.getElementById("biao1").innerText; var oInput = document.createElement('input'); oInput.value = Url2; document.body.appendChild(oInput); oInput.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 oInput.className = 'oInput'; oInput.style.display='none'; alert('复制成功'); } </script> <p cols="20" id="biao1">12345678</p> <input type="button" onClick="copyUrl2()" value="点击复制代码" />
Related recommendations:
The above is the detailed content of js copy text content to clipboard implementation code. For more information, please follow other related articles on the PHP Chinese website!