1. <script src="./cssjs/jquery.zclip.min.js" type="text/javascript"></script>
    2. <script>
    3. //复制文本到到剪贴版
    4. function copyToClipboard(index,maintext){
    5. var clip = new ZeroClipboard.Client();
    6. clip.setHandCursor( true );
    7. clip.setCSSEffects( true );
    8. clip.addEventListener( 'mouseDown', function(client){
    9. clip.setText( maintext );//绑定对应内容
    10. });
    11. clip.addEventListener( 'complete', function(){msgalert('复制成功');});
    12. clip.glue( 'btn-geturl'+index );//绑定对应ID
    13. }
    14. </script>
    15. /////////////////jquery.zclip.min.js/////////////////
    16. // Simple Set Clipboard System
    17. // Author: Joseph Huckaby
    18. var ZeroClipboard = {
    19. version: "1.0.7",
    20. clients: {}, // registered upload clients on page, indexed by id
    21. moviePath: './cssjs/ZeroClipboard.swf', // URL to movie
    22. nextId: 1, // ID of next movie
    23. $: function(thingy) {
    24. // simple DOM lookup utility function
    25. if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
    26. if (!thingy.addClass) {
    27. // extend element with a few useful methods
    28. thingy.hide = function() { this.style.display = 'none'; };
    29. thingy.show = function() { this.style.display = ''; };
    30. thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
    31. thingy.removeClass = function(name) {
    32. var classes = this.className.split(/\s+/);
    33. var idx = -1;
    34. for (var k = 0; k < classes.length; k++) {
    35. if (classes[k] == name) { idx = k; k = classes.length; }
    36. }
    37. if (idx > -1) {
    38. classes.splice( idx, 1 );
    39. this.className = classes.join(' ');
    40. }
    41. return this;
    42. };
    43. thingy.hasClass = function(name) {
    44. return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
    45. };
    46. }
    47. return thingy;
    48. },
    49. setMoviePath: function(path) {
    50. // set path to ZeroClipboard.swf
    51. this.moviePath = path;
    52. },
    53. dispatch: function(id, eventName, args) {
    54. // receive event from flash movie, send to client
    55. var client = this.clients[id];
    56. if (client) {
    57. client.receiveEvent(eventName, args);
    58. }
    59. },
    60. register: function(id, client) {
    61. // register new client to receive events
    62. this.clients[id] = client;
    63. },
    64. getDOMObjectPosition: function(obj, stopObj) {
    65. // get absolute coordinates for dom element
    66. var info = {
    67. left: 0,
    68. top: 0,
    69. width: obj.width ? obj.width : obj.offsetWidth,
    70. height: obj.height ? obj.height : obj.offsetHeight
    71. };
    72. while (obj && (obj != stopObj)) {
    73. info.left += obj.offsetLeft;
    74. info.top += obj.offsetTop;
    75. obj = obj.offsetParent;
    76. }
    77. return info;
    78. },
    79. Client: function(elem) {
    80. // constructor for new simple upload client
    81. this.handlers = {};
    82. // unique ID
    83. this.id = ZeroClipboard.nextId++;
    84. this.movieId = 'ZeroClipboardMovie_' + this.id;
    85. // register client with singleton to receive flash events
    86. ZeroClipboard.register(this.id, this);
    87. // create movie
    88. if (elem) this.glue(elem);
    89. }
    90. };
    91. ZeroClipboard.Client.prototype = {
    92. id: 0, // unique ID for us
    93. ready: false, // whether movie is ready to receive events or not
    94. movie: null, // reference to movie object
    95. clipText: '', // text to copy to clipboard
    96. handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
    97. cssEffects: true, // enable CSS mouse effects on dom container
    98. handlers: null, // user event handlers
    99. glue: function(elem, appendElem, stylesToAdd) {
    100. // glue to DOM element
    101. // elem can be ID or actual DOM element object
    102. this.domElement = ZeroClipboard.$(elem);
    103. // float just above object, or zIndex 99 if dom element isn't set
    104. var zIndex = 99;
    105. if (this.domElement.style.zIndex) {
    106. zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
    107. }
    108. if (typeof(appendElem) == 'string') {
    109. appendElem = ZeroClipboard.$(appendElem);
    110. }
    111. else if (typeof(appendElem) == 'undefined') {
    112. appendElem = document.getElementsByTagName('body')[0];
    113. }
    114. // find X/Y position of domElement
    115. var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
    116. // create floating DIV above element
    117. this.div = document.createElement('div');
    118. var style = this.div.style;
    119. style.position = 'absolute';
    120. style.left = '' + box.left + 'px';
    121. style.top = '' + box.top + 'px';
    122. style.width = '' + box.width + 'px';
    123. style.height = '' + box.height + 'px';
    124. style.zIndex = zIndex;
    125. if (typeof(stylesToAdd) == 'object') {
    126. for (addedStyle in stylesToAdd) {
    127. style[addedStyle] = stylesToAdd[addedStyle];
    128. }
    129. }
    130. // style.backgroundColor = '#f00'; // debug
    131. appendElem.appendChild(this.div);
    132. this.div.innerHTML = this.getHTML( box.width, box.height );
    133. },
    134. getHTML: function(width, height) {
    135. // return HTML for movie
    136. var html = '';
    137. var flashvars = 'id=' + this.id +
    138. '&width=' + width +
    139. '&height=' + height;
    140. if (navigator.userAgent.match(/MSIE/)) {
    141. // IE gets an OBJECT tag
    142. var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
    143. html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
    144. }
    145. else {
    146. // all other browsers get an EMBED tag
    147. html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
    148. }
    149. return html;
    150. },
    151. hide: function() {
    152. // temporarily hide floater offscreen
    153. if (this.div) {
    154. this.div.style.left = '-2000px';
    155. }
    156. },
    157. show: function() {
    158. // show ourselves after a call to hide()
    159. this.reposition();
    160. },
    161. destroy: function() {
    162. // destroy control and floater
    163. if (this.domElement && this.div) {
    164. this.hide();
    165. this.div.innerHTML = '';
    166. var body = document.getElementsByTagName('body')[0];
    167. try { body.removeChild( this.div ); } catch(e) {;}
    168. this.domElement = null;
    169. this.div = null;
    170. }
    171. },
    172. reposition: function(elem) {
    173. // reposition our floating div, optionally to new container
    174. // warning: container CANNOT change size, only position
    175. if (elem) {
    176. this.domElement = ZeroClipboard.$(elem);
    177. if (!this.domElement) this.hide();
    178. }
    179. if (this.domElement && this.div) {
    180. var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
    181. var style = this.div.style;
    182. style.left = '' + box.left + 'px';
    183. style.top = '' + box.top + 'px';
    184. }
    185. },
    186. setText: function(newText) {
    187. // set text to be copied to clipboard
    188. this.clipText = newText;
    189. if (this.ready) this.movie.setText(newText);
    190. },
    191. addEventListener: function(eventName, func) {
    192. // add user event listener for event
    193. // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
    194. eventName = eventName.toString().toLowerCase().replace(/^on/, '');
    195. if (!this.handlers[eventName]) this.handlers[eventName] = [];
    196. this.handlers[eventName].push(func);
    197. },
    198. setHandCursor: function(enabled) {
    199. // enable hand cursor (true), or default arrow cursor (false)
    200. this.handCursorEnabled = enabled;
    201. if (this.ready) this.movie.setHandCursor(enabled);
    202. },
    203. setCSSEffects: function(enabled) {
    204. // enable or disable CSS effects on DOM container
    205. this.cssEffects = !!enabled;
    206. },
    207. receiveEvent: function(eventName, args) {
    208. // receive event from flash
    209. eventName = eventName.toString().toLowerCase().replace(/^on/, '');
    210. // special behavior for certain events
    211. switch (eventName) {
    212. case 'load':
    213. // movie claims it is ready, but in IE this isn't always the case...
    214. // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
    215. this.movie = document.getElementById(this.movieId);
    216. if (!this.movie) {
    217. var self = this;
    218. setTimeout( function() { self.receiveEvent('load', null); }, 1 );
    219. return;
    220. }
    221. // firefox on pc needs a "kick" in order to set these in certain cases
    222. if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
    223. var self = this;
    224. setTimeout( function() { self.receiveEvent('load', null); }, 100 );
    225. this.ready = true;
    226. return;
    227. }
    228. this.ready = true;
    229. this.movie.setText( this.clipText );
    230. this.movie.setHandCursor( this.handCursorEnabled );
    231. break;
    232. case 'mouseover':
    233. if (this.domElement && this.cssEffects) {
    234. this.domElement.addClass('hover');
    235. if (this.recoverActive) this.domElement.addClass('active');
    236. }
    237. break;
    238. case 'mouseout':
    239. if (this.domElement && this.cssEffects) {
    240. this.recoverActive = false;
    241. if (this.domElement.hasClass('active')) {
    242. this.domElement.removeClass('active');
    243. this.recoverActive = true;
    244. }
    245. this.domElement.removeClass('hover');
    246. }
    247. break;
    248. case 'mousedown':
    249. if (this.domElement && this.cssEffects) {
    250. this.domElement.addClass('active');
    251. }
    252. break;
    253. case 'mouseup':
    254. if (this.domElement && this.cssEffects) {
    255. this.domElement.removeClass('active');
    256. this.recoverActive = false;
    257. }
    258. break;
    259. } // switch eventName
    260. if (this.handlers[eventName]) {
    261. for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
    262. var func = this.handlers[eventName][idx];
    263. if (typeof(func) == 'function') {
    264. // actual function reference
    265. func(this, args);
    266. }
    267. else if ((typeof(func) == 'object') && (func.length == 2)) {
    268. // PHP style object + method, i.e. [myObject, 'myMethod']
    269. func[0][ func[1] ](this, args);
    270. }
    271. else if (typeof(func) == 'string') {
    272. // name of function
    273. window[func](this, args);
    274. }
    275. } // foreach event handler defined
    276. } // user defined handler for event
    277. }
    278. };
    279. ///ZeroClipboard.swf///