无论浏览器如何复制textarea文本 [英] copying textarea text regardless of browser

查看:202
本文介绍了无论浏览器如何复制textarea文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一些我原本认为会很简单的事情,但事实并非如此,主要是为了让我可以在页面上放置一个textarea,并且有一个按钮可以允许用户可以在textarea中复制所有内容以粘贴到他们想要的位置,但是在经历了几次尝试和google-fu的很多应用程序之后,我还没有一个可行的示例,更不用说跨浏览器兼容。 / p>

所以我想我的问题有两个方面,这是可能的,如果是这样,是否可以这样做,使浏览器使用不是一个因素? p>

感谢您对此问题的帮助和回应。

可能,但在浏览器中并不一致。您可以使用jQuery插件剪贴板作为替代品。

这个插件在内部使用Flash对象来复制到剪贴板,这应该在浏览器中保持一致。



包含插件后,下面的代码应该可以工作:

  var text = $(textarea)。text(); 
$ .clipboard(text);

这会将文本区域中的所有内容复制到剪贴板。


I"m trying to do something that I originally thought would be quite simple, but it's turning out not to be. Mainly I'm trying to have so I can have a textarea on a page, with a button that would allow the user to copy everything within the textarea to paste wherever they wish. However after slogging through a few attempts and a lot of applications of google-fu, I've yet to have an example that works, much less is cross browser compatible.

So I guess my question is two fold; is this possible, and if so, is this able to be done so that the browser used isn't a factor?

Thanks for your help and responses to this question.

解决方案

This is possible, but isn't consistent across browsers. You can use the jQuery plugin Clipboard as a substitute.

This plugin uses a Flash object internally to copy to the clipboard, which should be consistent across browsers.

With the plugin included, the following code should work:

var text = $("textarea").text();
$.clipboard(text);

That will copy everything in the text area to the clipboard.

这篇关于无论浏览器如何复制textarea文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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