下载
使用
<!-- 要复制的区域 -->
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git">
<!-- 复制按钮,关联idd为foo的 -->
<button class="btn" data-clipboard-target="#foo">
<img src="assets/clippy.svg" alt="Copy to clipboard">
</button>
<script>
// JS也必须要new一个出来否则无法正常使用
var clipboard=new ClipboardJS('.btn');
clipboard.on('success',function(e){
console.log(e);
})
clipboard.on('error',function(e){
console.log(e);
})
</script>