1.引入 https://cdn.bootcss.com/clipboard.js/1.7.1/clipboard.min.js
2.html <button type="button" class="copy">点击复制</button>
3. var txt = '要复制的内容';
var clipboard = new Clipboard('.copy', {
text: function () {
return txt;
}
});
clipboard.on('success', function(e) {
console.log('复制成功')
e.clearSelection();
});
clipboard.on('error', function(e) {
console.log('请选择“拷贝”进行复制!');
});