创建时间:2022-05-06
<div id="content">需要复制的内容</div>
<button onclick="copy()">复制</button>
<script>
function copy() {
var oInput = document.createElement("input"); //创建一个隐藏input(重要!)
oInput.value = document.getElementById("content").innerHTML; //需要复制的内容
document.body.appendChild(oInput);
oInput.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
oInput.className = "oInput";
oInput.style.display = "none";
alert("复制成功");
}
</script>上一篇:vue3.2,组件中,匿名插槽,具名插槽,作用域插槽
下一篇:仿阿里云雪碧图动画