-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
83 lines (80 loc) · 2.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!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>