js+swf 控制clipboard
貌似近期跟剪切板对上了,js控制剪切板在兼容浏览器上比较蛋疼。在网上找了几个程序,测试后感觉还是jQuery ZeroClipboard好用一些。
下面代码兼容所有浏览器, 看代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
<!DOCTYPE html> <html> <head> <title>ZeroClipboard Test</title> <meta charset="utf-8"> <style type="text/css"> .line{margin-bottom:20px;} </style> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.zclip.js"></script> </head> <body> <div class="line"> <h2>demo点击复制表单中的文本</h2> <a href="#none" class="copy-input input1">点击复制单中的文本</a> <input type="text" class="input " value="输入要复制的内容" /> </div> </body> </html> <script type="text/javascript"> $(document).ready(function(){ if(!window.clipboardData) {//初始化 判断是否为IE $(".copy-input").each(function(){ $(this).removeClass('input1'); //移除IE剪切板事件 }) $(".copy-input").zclip({ path: "ZeroClipboard.swf", copy: function(){ return $(this).parent().find(".input").val(); }, afterCopy:function(){// 复制成功后的操作 alert("已复制到剪切板"); } }); } $('.input1').click(function(){ window.clipboardData.setData('text',$(this).parent().find(".input").val()); alert("已复制到剪切板"); }); }); </script> |
暂无评论