zeroclipboard火灾点击事件通过jquery [英] zeroclipboard fire click event via jquery

查看:129
本文介绍了zeroclipboard火灾点击事件通过jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ZeroClipboard是一个javascript + flash脚本,允许浏览器将文本放入剪贴板,它会在选定的元素上放置一个透明的闪光,当你点击它,你可以插入文本到剪贴板,这是工程,没有问题,但我想让它自动。
在剪贴板中加载一个字符串,以便用户能够粘贴它。一些代码
main.js

ZeroClipboard is a javascript + flash script that allows the browser to put text into the clipboard, it puts a transparent flash over the selected element , and when you click it you can insert text into the clipboard, this works, no problem, but i want to make it automatic. Onload put a string in the clipboard, for the user to be able to paste it latter. Some code main.js

$('document').ready(function() {
ZeroClipboard.setMoviePath("http://url/to/ZeroClipboard.swf");
  var clip=new ZeroClipboard.Client();
 clip.on( 'load', function(client) {
   clip.glue('#redirlink');
} );
});

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-gb" lang="en-gb" dir="ltr" >
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="main.js"></script>

    <title>TEST</title>
  </head>
  <body>


      <div >
     <a  id="redirlink" data-clipboard-text="abcd" href="http://alabala.com" >Click HERE</a>

    </div>

  </body>
</html>

ok现在的问题是如何在zeroClipboard上模拟点击事件?我试过, $('#obkect_id)。click(); 它不工作(事件触发,但它没有影响剪贴板,

ok now the question is how can i simulate a click event on the the zeroClipboard puts? i have tried with , $('#obkect_id").click(); it doesn't work (the event fires, but it has no effect on the clipboard, but when i click with the mouse, it works). Is there any way i can achieve that?

推荐答案

最新版本的ZeroClipboard已经取消了Client(),因此代码也改变了一点
下载最新版本github 这里

The newest versions of ZeroClipboard have done away with Client(). Hence the code changes a bit too. Download the latest version from Github here

然后说你想在页面/元素加载时更新/放置一些字符串说点击'id'剪贴板需要加载一些文本

Also then say you want to update/put some string when page/element loads. Say on clicking the 'element' having id '#id', the clipboard needs to be loaded with some text

<script>
var str = 'Some text';
$('element').attr('data-clipboard-text','str');
ZeroClipboard.setDefaults({moviePath:'http://...../ZeroClipboard.swf'});
var clip = new ZeroClipboard($('#id'));
clip.on('complete',function(client, args){
alert('Copied');
});
</script>

希望这有助于

这篇关于zeroclipboard火灾点击事件通过jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆