1. 程式人生 > >clipboard 實現複製

clipboard 實現複製

 

html

<textarea id="bar" cols="62" rows="5" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">3dd</textarea>
<button class="btn" data-clipboard-action="copy" data-clipboard-target="#bar">複製</button>

js

 

<script>
var clipboard = new Clipboard('.btn');
clipboard.on('success', function(e) {
console.info('Action:', e.action);
console.info('Text:', e.text);
console.info('Trigger:', e.trigger);
alert("複製成功");
e.clearSelection();
});

clipboard.on('error', function(e) {
console.error('Action:', e.action);
console.error('Trigger:', e.trigger);
});

</script>

其實最主要的還要一個指令碼:<script src="js/clipboard.min.js" type="text/javascript"></script>
指令碼下載地址:

http://download.csdn.net/download/u014266877/9715481