感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
/**
* jQuery/Js 复制文本到剪贴板的示例
* @param
* @arrange (512.笔记) jb51.cc
**/
<!doctype html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<title>jQuery/Js复制文本到剪贴板</title>
<script src="http://apps.bdimg.com/libs/jquery/1.8.3/jquery.js"></script>
<script type="text/javascript" src="http://www.jq22.com/demo/copy20161120/dist/clipboard.min.js"></script>
</head>
<body>
<div id="demo">http://www.baidu.com</div>
<button class="btn">复制</button>
<script>
var content = $("#demo").html();
var clipboard = new Clipboard('.btn',{
text: function() {
return content;
}
});
clipboard.on('success',function(e) {
alert("复制成功");
});
clipboard.on('error',function(e) {
console.log(e);
});
</script>
</body>
</html>