简体   繁体   English

复制文本框的按钮

[英]Button to Copy a Text Box

I need a simple script that gives me a button that when clicked will copy the contents of a text input box to the clipboard. 我需要一个简单的脚本,该脚本可以为我提供一个按钮,单击该按钮会将文本输入框的内容复制到剪贴板。 Or it could be a script that when you click on the text input box, automatically copies the contents to the clipboard and displays a "Copy" message next to the text input box. 也可能是一个脚本,当您单击文本输入框时,会自动将内容复制到剪贴板,并在文本输入框旁边显示“复制”消息。

I've seen them all over the web, but can't find the code for one now. 我已经在网上看到了它们,但是现在找不到它们的代码。

This example uses jQuery : 这个例子使用jQuery

Assuming an input box with an id of foo , and a button with an id of clickme , here's how I'd do it: 假设输入框的ID为foo ,按钮的ID为clickme ,这是我的操作方法:

var inputText = "";
$("#clickme").click(function() {
    inputText = $("#foo").val();
});
// inputText now has the input box's value

Edit: 编辑:

After your clarification, I now understand what you are trying to do. 在您澄清之后,我现在了解您正在尝试做什么。 Unfortunately, flash 10 broke most of the methods to do this. 不幸的是,Flash 10破坏了大多数方法。 However, some great people wrote ZeroClipboard , which is fully compatible with flash 10 and makes it really easy to accomplish this task. 但是,一些很棒的人写了ZeroClipboard ,它与Flash 10完全兼容,并且非常容易完成此任务。 Their wiki explains usage. 他们的维基解释了用法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM