<button onclick="copyToClip('我是要复制的内容')"> Copy </button>
<script type="text/javascript">
function copyToClip(content) {
var aux = document.createElement("input"); // 创建元素用于复制
aux.setAttribute("value", content); // 内容content放入元素
document.body.appendChild(aux); // 将元素插入页面进行调用
aux.select();// 选择内容
document.execCommand("copy");// 将内容复制到系统剪贴板
document.body.removeChild(aux);// 删除创建元素
alert("复制成功:" + aux.value);// 提示复制成功
}
</script>
js点击复制txt到剪贴板
最新推荐文章于 2024-03-19 19:45:18 发布