现代化的“复制到剪切板”插件。不包含 Flash。gzip 压缩后仅 3kb。
A modern approach to copy text to clipboard
No Flash. No frameworks. Just 3kb gzipped
Copying text to the clipboard shouldn't be hard. It shouldn't require dozens of steps to configure or hundreds of KBs to load. But most of all, it shouldn't depend on Flash or any bloated framework.
That's why clipboard.js exists.
网盘下载地址:https://pan.baidu.com/s/1x6cD1U5ALiryZkecygOizg
下载后JS放在clipboard.js-masterdist
使用示例:
代码语言:javascript复制<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>target-input</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- 1. Define some markup -->
<input id="foo" type="text" value="hello">
<button class="btn" data-clipboard-action="copy" data-clipboard-target="#foo">Copy</button>
<!-- 2. Include library -->
<script src="../dist/clipboard.min.js"></script>
<!-- 3. Instantiate clipboard -->
<script>
var clipboard = new ClipboardJS('.btn');
clipboard.on('success', function(e) {
console.log(e);
});
clipboard.on('error', function(e) {
console.log(e);
});
</script>
</body>
</html>
官网:https://clipboardjs.com/
GitHub地址:https://github.com/zenorocha/clipboard.js/