javascript ZeroClipboard - 如何使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15813332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 02:11:43  来源:igfitidea点击:

ZeroClipboard - How to use

javascriptcopyzeroclipboard

提问by Armesh Singh

I'm using this one http://jonrohan.github.io/ZeroClipboard/

我正在使用这个http://jonrohan.github.io/ZeroClipboard/

I spent this whole day figuring out how to use ZeroClipboard(ZC). I even read the instructions: https://github.com/jonrohan/ZeroClipboard/blob/master/docs/instructions.mdand followed it step by step and couldn't do it.

我花了一整天的时间来弄清楚如何使用 ZeroClipboard(ZC)。我什至阅读了说明:https: //github.com/jonrohan/ZeroClipboard/blob/master/docs/instructions.md并按照它一步一步来,无法做到。

I tried again and again and again but I just can't get it to work. I even spent hours reading other guides at stackoverflow and other pages both just couldn't get this to work. Moreover, most of the answers are outdated.

我一次又一次地尝试,但我就是无法让它工作。我什至花了几个小时阅读 stackoverflow 上的其他指南,而其他页面都无法让它发挥作用。此外,大多数答案已经过时。

Can anyone please write a simple working ZC code that copies a paragraph tag:

任何人都可以写一个简单的工作 ZC 代码来复制一个段落标签:

<p>Hello, I'm Armesh</p> 

Then just tell me simply each part of the ZC code and why you wrote it that way.

然后简单地告诉我 ZC 代码的每个部分以及你为什么这样写。

I plan to use ZC to copy references generated by my generator: http://anonoz.com/armesh/

我打算使用 ZC 来复制我的生成器生成的引用:http: //anonoz.com/armesh/

This is the code I wrote, all link references are correct:

这是我写的代码,所有链接引用都是正确的:

<!DOCTYPE HTML>
<html>
<head>
    <title>Zero Test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="javascripts/ZeroClipboard.js"></script>
</head>

<script language="JavaScript">
$(document).ready(function() {

  var clip = new ZeroClipboard($("#copy_button"), {
      moviePath: "javascripts/ZeroClipboard.swf"
    });     
});
</script>

<body>
<button id='#copy_button' data-clipboard-target='to_copy'><b>Copy To Clipboard</b></button>

<p id='to_copy'>123456</p>

</body>
</html>

I also ran the code/web page above in Google Chrome, there are no errors log in the console. It's blank.

我还在 Google Chrome 中运行了上面的代码/网页,控制台中没有错误日志。它是空白的。

回答by Armesh Singh

Ok I got it working, I also think the code posted above by me is correct.

好的,我开始工作了,我也认为我上面发布的代码是正确的。

The problem was that I was testing on local, and browsers usually prevent flash from running locally. This is what caused it to fail despite the code being correct.

问题是我在本地测试,浏览器通常会阻止flash在本地运行。尽管代码是正确的,但这就是导致它失败的原因。

As a last resort, I uploaded to my web server and tried online, it worked fine.

作为最后的手段,我上传到我的网络服务器并在线尝试,它工作正常。

So, always test ZeroClipboard online after uploading it to your Web Server.

因此,始终在将 ZeroClipboard 上传到您的 Web 服务器后在线测试它。

回答by MoNoX

There is a Bug in your Code! Look at the button id-attribute and delete the '#' !

您的代码中存在错误!查看按钮 id-attribute 并删除 '#' !

And: If u want more than 1 Clipboard Button on the current Page use the class attribute instead of id.

并且:如果您想要在当前页面上有 1 个以上的剪贴板按钮,请使用 class 属性而不是 id。

It works fine now! ;)

它现在工作正常!;)

回答by de_nuit

You can test ZeroClipboard locally by adding the port 3000. e.g. http://localhost:3000

您可以通过添加端口 3000 在本地测试 ZeroClipboard。例如 http://localhost:3000