clipboard.js(官网:http://zenorocha.github.io/clipboard.js/)
引入的clipboard.min.js只有10k左右
目前支持Chrome,safari,IE,FireFox等主流浏览器,demo如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>target-div</title>
</head>
<body>
<span id="copyValue">hello</span>
<button class="btn" id="copyId" data-clipboard-action="copy" data-clipboard-target="#copyValue">Copy</button>
<script src="../clipboard.min.js"></script>
<script>
var clipboard = new Clipboard('#copyId');
clipboard.on('success', function(e) {
e.clearSelection();
console.log(e);
});
clipboard.on('error', function(e) {
e.clearSelection();
console.log(e);
});
</script>
</body>
</html>
用起来非常简单,推荐使用(https://blog.csdn.net/ludesming/article/details/82496949)。