<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>复制演示</title>
<style>
.wrapper {
position: relative;
top:-500px;
}
</style>
</head>
<body>
<div class="wrapper">
<p id="text" style="display: none">这里是要复制的内容</p>
<textarea id="input">fuzhi</textarea>
</div>
<a class="botton" onclick="copyText()">点击复制</a>
<script>
function copyText() {
var text = document.getElementById("text").innerText;
var input = document.getElementById("input");
input.value = text; // 修改文本框的内容
input.select(); // 选中文本
document.execCommand("copy"); // 执行浏览器复制命令
toast.text({
title: '复制成功!',
duration: 1700
});
return false;
}
</script>
</body>
</html>
网友评论