1. 程式人生 > >clipboard.js複製文字到剪下板

clipboard.js複製文字到剪下板

  <a title="複製連結地址" id="copyId" data-clipboard-text="${siteUrl}/subject/view.jhtml?id=${subject.id}" ></a>
<script type="text/javascript" src="/js/clipboard.min.js"></script>

<script type="text/javascript">  	
	var clipboard = new ClipboardJS('#copyId');
	clipboard.on('success', function(e) {
	    console.info('Action:', e.action);
	    console.info('Text:', e.text);
	    console.info('Trigger:', e.trigger);
		layer.msg("複製成功");
	    e.clearSelection();
	});
	
	clipboard.on('error', function(e) {
	    console.error('Action:', e.action);
	    console.error('Trigger:', e.trigger);
	});
</script>

此處提供clipboard.min.js的下載地址
http://download.csdn.net/download/sinat_28505133/10273046