注意:class=' btn' ,必要的
html代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery复制文本到剪贴板</title>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.jq22.com/demo/clipboard.js-master201703170013/dist/clipboard.min.js"></script>
</head>
<body>
<button class="btn copyCode">复制</button>
<script>
var clipboard = new Clipboard('.copyCode', {
text: function() {
return '我是复制文本123';
}
});
clipboard.on('success', function(e) {
alert("复制成功");
});
clipboard.on('error', function(e) {
console.log(e);
});
</script>
</body>
</html>
网友评论