复制文本内容到剪贴板
文章目录
input输入框中的内容可以复制
通过创建input间接实现复制div中的文本
<body>
<div id="box">123456789</div>
<input type="button" onClick="copyText()" value="点击复制" />
</body>
<script type="text/javascript">
function copyText(){
var sText = document.getElementById("box").innerText;
var oInput = document.createElement('input');
oInput.value = sText;
document.body.appendChild(oInput);
oInput.select(); // 选择对象
document.execCommand("copy"); // 执行浏览器复制命令
document.body.removeChild(oInput);
}
</script>

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论