https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md
javascript
https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/api/ZeroClipboard.Core.md css
The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface. The "Zero" signifies that the library is invisible and the user interface is left entirely up to you. html
使用:java
一、引入js文件,記得先引入jqueryjquery
<script type="text/javascript" src="ZeroClipboard.js"></script>
二、而後配置swf文件的路徑git
ZeroClipboard.config( { swfPath: "http://YOURSERVER/path/ZeroClipboard.swf" } );
三、建立客戶端github
var client = new ZeroClipboard($(".copy-button"));
四、使用copy功能ajax
client.on( "copy", function (event) { var clipboard = event.clipboardData; clipboard.setData( "text/plain", "Copy me!" ); alert('copy over!); // clipboard.setData( "text/html", "<b>Copy me!</b>" ); // clipboard.setData( "application/rtf", "{\\rtf1\\ansi\n{\\b Copy me!}}" ); });
簡單使用ok!api
下面附上一個完整的例子:app
<html> <head> <style type="text/css"> .clip_button { text-align: center; border: 1px solid black; background-color: #ccc; margin: 10px; padding: 10px; } .clip_button.zeroclipboard-is-hover { background-color: #eee; } .clip_button.zeroclipboard-is-active { background-color: #aaa; } </style> </head> <body> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript" src="ZeroClipboard.js"></script> <div class="clip_button">Copy To Clipboard</div> <div class="clip_button">Copy This Too!</div> <script type="text/javascript"> var client = new ZeroClipboard( $('.clip_button') ); client.on( 'ready', function(event) { // console.log( 'movie is loaded' ); client.on( 'copy', function(event) { event.clipboardData.setData('text/plain', event.target.innerHTML); } ); client.on( 'aftercopy', function(event) { console.log('Copied text to clipboard: ' + event.data['text/plain']); } ); } ); client.on( 'error', function(event) { // console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message ); ZeroClipboard.destroy(); } ); </script> </body></html>