目前最好用的“点击复制”功能,兼容主流浏览器

<div class="demo-area">
  <button id="d_clip_button" class="my_clip_button" title="Click me to copy to clipboard." data-clipboard-target="fe_text" data-clipboard-text="Default clipboard text from attribute"><b>Copy To Clipboard...</b></button>
  <h4><label for="fe_text">Change Copy Text Here</label></h4>
  <textarea id="fe_text"  cols="50" rows="3">Copy me!</textarea>
</div>
<h4>Debug Console:</h4>
<div id="d_debug"></div>


<script type="text/javascript" src="ZeroClipboard.min.js"></script>
<script language="JavaScript">

$(document).ready(function() {
var clip = new ZeroClipboard($("#d_clip_button"), {
  moviePath: "ZeroClipboard.swf"
});

clip.on('load', function (client) {
  debugstr("Flash movie loaded and ready.");
});

clip.on('noFlash', function (client) {
  $(".demo-area").hide();
  debugstr("Your browser has no Flash.");
});

clip.on('wrongFlash', function (client, args) {
  $(".demo-area").hide();
  debugstr("Flash 10.0.0+ is required but you are running Flash " + args.flashVersion.replace(/,/g, "."));
});

clip.on('complete', function (client, args) {
  debugstr("Copied text to clipboard: " + args.text);
});

// jquery stuff (optional)
function debugstr(text) {
  $("#d_debug").append($("<p>").text(text));
}

});

</script>


下载地址:DEMO+全部文件


为什么下载的DEMO不能运行,点击不能复制?

答:这个必须运行在真实环境上,直接用浏览器打开是不行的,用IIS运行就可以。


使用方法:

导入 ZeroClipboard.js 文件: 


<script type="text/javascript" src="ZeroClipboard.js"></script> 


附上项目实际使用的代码:

$(document).ready(function() {
	//要点击对象
	var objName="#contact_door_text";
	var clip = new ZeroClipboard($(objName), {
	  moviePath: "script/ZeroClipboard.swf"
	});
	
	//提示复制成功
	clip.on('complete', function (client, args) {
	  alert("已复制到剪切板!");
	});
});






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值