JS实现复制
test.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
button {
height: 35px;
width: 100px;
margin-top: 10px;
}
input {
height: 26px;
margin-top: 10px;
padding: 4px;
}
</style>
</head>
<body>
<input type="text" name="test" id="test" readonly="readonly" value="我是测试的文本信息" />
<br>
<button onclick="copyUrl()">点击复制</button><br>
<input type="text" name="" id="" value="" placeholder="请输入复制的信息" />
</body>
<script>
function copyUrl() {
var Url = document.getElementById("test");
Url.select();
document.execCommand("Copy");
alert("已复制好,可贴粘。");
}
</script>
</html>
效果图:
点击效果图
弹框: