This article mainly introduces the relevant information of JavaScript using ZeroClipboard to operate the clipboard. It has certain reference value. Interested friends can For reference
1. ZeroClipboard download address
provides you with a detailed download address of ZeroClipboard:
Zero Clipboard open source JavaScript+flash copy library class
Copy and paste website content based on ZeroClipboardJS special effectsSource code
zeroclipboard Copy to cut implemented with js and flash Board file
2. Add jsreference
<script src="../Assets/js/jquery-1.8.3.min.js"></script> <script src="../Assets/js/ZeroClipboard/ZeroClipboard.js"></script>
$(function () { InitCopyToClipboard('btnCopyToClipBoard'); }); //将内容复制到剪切板 function InitCopyToClipboard(btnId) { ZeroClipboard.setMoviePath("../Assets/js/ZeroClipboard/ZeroClipboard.swf"); //设置flash文件在项目中的位置 var clip = new ZeroClipboard.Client(); // 新建一个对象 clip.setHandCursor(true); clip.addEventListener('onmouseup', function (client) { //创建监听 // 可以在这儿写一个方法处理相应的事件逻辑 clip.setText('要复制到剪切板中的内容'); }); clip.glue(btnId); //将flash覆盖至指定ID的DOM上 //窗口大小发生变化时从新将flash覆盖至制定的id上,否则位置不对应导致点击时没反应 bind(window, "resize", function () { clip.reposition(); }); return false; } /************************************ * 添加事件绑定 * @param obj : 要绑定事件的元素 * @param type : 事件名称。不加 "on". 如 : "click" 而不是 "onclick". * @param fn : 事件处理函数 ************************************/ function bind(obj, type, fn) { if (obj.attachEvent) { obj['e' + type + fn] = fn; obj[type + fn] = function () { obj['e' + type + fn](window.event); } obj.attachEvent('on' + type, obj[type + fn]); } else obj.addEventListener(type, fn, false); }
The above is the detailed content of Code sharing on how JavaScript uses ZeroClipboard to operate the clipboard. For more information, please follow other related articles on the PHP Chinese website!