1. 程式人生 > >Clipboard.js 複製內容到剪下板 ,不用Flash

Clipboard.js 複製內容到剪下板 ,不用Flash

<script type="text/javascript" src="clipboard.min.js" ></script>


<textarea id="bar2" cols="62" rows="5" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">adadqdqwdvdfvdfdfgergergergergdfbddfg</textarea>




<a class="fz" data-clipboard-action="copy" data-clipboard-target="#bar2">複製內容</a>



var clipboard = new Clipboard('.fz');
		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);
		});


html也可以直接這樣:

<a href="javascript:;" class="fz" data-clipboard-action="copy" data-clipboard-text="需要複製的內容" >複製連結</a>


clipboard.min.js下載:

http://download.csdn.net/download/macwhirr123/9897836

參考連結:

http://www.paipk.com/503.html

http://www.jb51.net/article/72996.htm

https://github.com/zenorocha/clipboard.js