加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.html 2.70 KB
一键复制 编辑 原始数据 按行查看 历史
xuliangzhan 提交于 2020-02-12 12:31 . update
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
<title>剪贴板测试页面</title>
<script src="https://cdn.jsdelivr.net/npm/xe-clipboard" async></script>
<style type="text/css">
.copy-status {
height: 60px;
text-align: center;
font-size: 20px;
font-weight: 700;
}
.copy-status>span {
display: none;
}
.copy-status.success {
color: green;
}
.copy-status.success>.success {
display: block;
}
.copy-status.error {
color: red;
}
.copy-status.error>.error {
display: block;
}
</style>
</head>
<body>
<noscript>
<strong>We're sorry but vxe-table doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div>
<div class="copy-status">
<span class="success">Copy success.</span>
<span class="error">The browser is not supported.</span>
</div>
<button class="btn1">复制到内容111</button>
<input type="text" value="复制到内容222">
<button class="btn2">复制</button>
<input type="text" value="剪贴内容333">
<button class="btn3">剪贴</button>
</div>
<script>
(function () {
var showtimeout
function copyEvent (text) {
clearTimeout(showtimeout)
if (XEClipboard.copy(text)) {
document.querySelector('.copy-status').className = 'copy-status success'
} else {
document.querySelector('.copy-status').className = 'copy-status error'
}
showtimeout = setTimeout(function () {
document.querySelector('.copy-status').className = 'copy-status'
}, 1500)
}
document.querySelector('.btn1').addEventListener('click', function (evnt) {
copyEvent(evnt.target.innerText)
})
document.querySelector('.btn2').addEventListener('click', function (evnt) {
let inpElem = evnt.target.previousElementSibling
copyEvent(inpElem.value)
})
document.querySelector('.btn3').addEventListener('click', function (evnt) {
let inpElem = evnt.target.previousElementSibling
copyEvent(inpElem.value)
inpElem.value = ''
})
})()
</script>
<script src="https://cdn.jsdelivr.net/npm/xe-utils" async></script>
<script src="https://cdn.jsdelivr.net/npm/xe-ajax" async></script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化