开发者

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:

Assuming an input box with an id of foo, and a button with an id of clickme, here's how I'd do it:

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. However, some great people wrote ZeroClipboard, which is fully compatible with flash 10 and makes it really easy to accomplish this task. Their wiki explains usage.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜