<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
.wrapper{
position: relative;
}
#input{
position: absolute;
top: 0;
left: 0;
opacity: 0;
z-index: -10;
}
</style>
</head>
<body>
<div class="wrapper">
<p id="text">复制文本</p>
<textarea id="input" >heishou</textarea>
<button οnclick="copyText()">copy</button>
</div>
<script type="text/javascript">
function copyText(){
var text = document.getElementById("text").innerText;
var input = document.getElementById("input");
input.value = text;
input.select();
document.execCommand("copy");
alert("复制成功!");
}
</script>
</body>
</html>
复制文本
最新推荐文章于 2024-03-12 07:00:00 发布