2011-02-25 41 views
1

认为这应该是一个容易的...我想使用jquery的select()函数获取当前选定的文本。jquery get select()选择

$('textarea').select(function(selection) { 
    alert(selection); 
}); 

这将返回[对象对象] ...如何返回选定的文本?

非常感谢

+0

选定的文本选择框的选择选项文本? – Sarfraz 2011-02-25 10:49:50

+0

我想返回文本区域内的选定文本 – Tim 2011-02-25 10:51:10

回答

4

从jQuery的选择()DOC:

检索当前 所选文本的方法不同于一个浏览器 到另一个。一些jQuery 插件提供跨平台 解决方案。

一个快速谷歌搜索 “的jquery获取所选文本” 打开了这一点:

http://motyar.blogspot.com/2010/02/get-user-selected-text-with-jquery-and.html
这样的:
http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html
和更多

在p年龄或
+0

您的Google搜索能力超出了我的范围:)谢谢Andy,非常方便。 – Tim 2011-02-25 11:01:09