js,jquery点击复制到剪贴板插件clipboard.js的使用

时间:2022-11-24 19:35:59
clipboard.js插件自己去下载这东西兼容性还不错,之前用那个不兼容火狐果断去掉 http://www.jq22.com/demo/copy20161120/dist/clipboard.min.js
// 插件代码是jquery插件库里的

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>function-text</title>
</head>
<body>
<button class="btn">Copy</button>
<div id="c">你是个大sb</div>
<script src="./clipboard.js"></script>
<script>
var c = document.getElementById("c");
var s=c.innerHTML;
var clipboard = new Clipboard('.btn', {
text: function() {
return s;
}
});
clipboard.on('success', function(e) {
alert("复制成功");
});

clipboard.on('error', function(e) {
console.log(e);
});

</script>
</body>
</html>