1、引用js路劲
<script type="text/javascript" src="./dist/clipboard.min.js"></script>
2、编写代码
html
<input type="text" id="copyVal" readonly value="被复制内容" />
<button class="copyBtn" >点击复制</button>
js
//实例化 ClipboardJS对象;
var copyBtn = new ClipboardJS('.copyBtn');
copyBtn.on("success",function(e){
// 复制成功
alert("复制成功");
e.clearSelection();
});
copyBtn.on("error",function(e){
//复制失败;
alert("复制失败");
console.log( e.action )
});