<script> function handleCopy(data) { var oInput = document.createElement("input"); oInput.style.border = "0 none"; oInput.style.color = "transparent"; oInput.value = data; document.body.appendChild(oInput); oInput.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 alert("复制" + oInput.value + "成功"); oInput.parentNode.removeChild(oInput); } </script> 兼容:IE7版本及以上
前端实现拷贝功能
<div id="copyEl" onclick="handleCopy('123456789')">123456</div>
<script> function handleCopy(data) { var oInput = document.createElement("input"); oInput.style.border = "0 none"; oInput.style.color = "transparent"; oInput.value = data; document.body.appendChild(oInput); oInput.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 alert("复制" + oInput.value + "成功"); oInput.parentNode.removeChild(oInput); } </script> 兼容:IE7版本及以上
<script> function handleCopy(data) { var oInput = document.createElement("input"); oInput.style.border = "0 none"; oInput.style.color = "transparent"; oInput.value = data; document.body.appendChild(oInput); oInput.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 alert("复制" + oInput.value + "成功"); oInput.parentNode.removeChild(oInput); } </script> 兼容:IE7版本及以上