如何选择文本框中的所有文本并使用JavaScript / jQuery将其复制到剪贴板?
我的文本框旁边有一个添加到剪贴板按钮。每当按下复制到剪贴板按钮时,我希望剪贴板的内容被复制到剪贴板,并以跨浏览器的方式跨Internet Explorer,Firefox,Chrome,Opera等工作。我可以使用 jQuery 或plain JavaScript 。
I have a textbox with an 'Add to clipboard' button next to it. Whenever the copy to clipboard button is pressed, I want the contents of the clipboard to get copied to the clipboard, and work in a cross browser way across Internet Explorer, Firefox, Chrome, Opera, etc. I can use jQuery or plain JavaScript.
如何做到这一点?
听起来像 jQuery剪贴板插件可能会很好地完成工作。您也可以使用选择符表示法,或者实用程序 $。复制
Sounds like the jQuery clipboard plugin might do the job well. You can use the selector notation with it too, ot the utility $.copy
编辑:
ZeroClipboard 是另一种选择,这看起来似乎是运作良好(在Firefox 3.5,IE 6中测试过)和Chrome)
ZeroClipboard is another choice and this does appear to work well (tested in Firefox 3.5, IE 6 and Chrome)