clipboard.js实现复制到剪切板
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <main class="wrap"> <div id="example-text" class="example"> <div data-clipboard-demo data-clipboard-action="copy" data-clipboard-text="hhaaaaaaah">Copy to clipboard</div> </div> <script src="https://clipboardjs.com/dist/clipboard.min.js"></script> <script >
var clipboardDemos=new ClipboardJS('[data-clipboard-demo]');
//复制成功后的回调
clipboardDemos.on('success',function(e){
e.clearSelection();//释放内存
console.info('Text:',e.text);
});
//复制失败后的回调
clipboardDemos.on('error',function(e){
});
</script> </body> </html>