jQuery ZeroClipboard粘贴板

网页中偶尔需要复制链接到粘贴板里,然后粘贴分享。为了用户体验都不好意思对客户说“请使用右键复制粘贴”,都需要给一个按钮点一下就复制了内容。此做法常常用到的就是execCommand("Copy")。可惜只IE支持,但无法兼容。今天介绍一款FLASH粘贴板,兼容所有浏览器,但必须得安装了FLASH插件哦。

jQuery ZeroClipboard v1.1.1
官网:http://steamdev.com/zclip 全英文哦,英语要是好点就直接进去看看

事先请准备三个文件:
1、jquery.js
2、jquery.zclip.js ~16KB 源始版    或者下载压缩版jquery.zclip.min.js ~7KB 
3、ZeroClipboard.swf ~1KB

使用例子:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">   
  3. <head>   
  4.     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />   
  5.     <title>jquery.zclip</title>    
  6. <script type="text/javascript" src="jquery1.4.2.js"></script>   
  7. <script type="text/javascript" src="jquery.zclip.js"></script>   
  8. <body><input type="text" name="text" id="text" value="http://www.baidu.com" />   
  9. <a href="javascript:void(0)" id="dynamic">复制</a>   
  10.   
  11. <script type="text/javascript">   
  12. $(document).ready(function(){   
  13.     $("#dynamic").zclip({   
  14.         path:'ZeroClipboard.swf',   
  15.         copy:$('#text').text()   
  16. });   
  17. </script>   
  18. </body>   
  19. </html>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>jquery.zclip</title>	
<script type="text/javascript" src="jquery1.4.2.js"></script>
<script type="text/javascript" src="jquery.zclip.js"></script>
<body><input type="text" name="text" id="text" value="http://www.baidu.com" />
<a href="javascript:void(0)" id="dynamic">复制</a>

<script type="text/javascript">
$(document).ready(function(){
    $("#dynamic").zclip({
        path:'ZeroClipboard.swf',
        copy:$('#text').text()
});
</script>
</body>
</html>

 文件打包下载:点击下载 jQuery ZeroClipboard粘贴板 - 舞王万岁万万岁 -

使用注意:我们曾做一个案例时,发觉只有第一次复制有效,之后就无法复制。原来是我们多次运行$(id).zclip();造成的,也就是说针对同一个id你只能执行一次$(id).zclip(),假如你非要执行第二次,请你删除这个id再建一个相同的id来执行$(id).zclip()。

其他参数设置:

Settings
Variable
Default Value
Available Values
path *"ZeroClipboard.swf""path/to/ZeroClipboard.swf"
copy *nullany string, or any javascript expression or function that returns a string
afterCopynullspecify a function to call after text is copied.

(your afterCopy function will overwrite the default alert box.)
beforeCopynullspecify a function to call before text is copied.
clickAftertruetrue
false
setHandCursortruetrue
false
setCSSEffectstruetrue
false
* required
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值