使用jquery .select()获得突出显示的文本? [英] get highlighted text using jquery .select()?

查看:113
本文介绍了使用jquery .select()获得突出显示的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在此处找到示例代码 http://api.jquery.com/select/

I was trying example code found here http://api.jquery.com/select/

$(":input").select( function () { 
      $("div").text("Something was selected").show().fadeOut(1000); 
    });

现在我的问题是代替打印已选择某项内容",我可以获取确切的所选文本吗?

Now my question is instead of printing "Something was selected" , can I get exact selected text?

我想要jquery .select()特定答案.我从此处

I want jquery .select() specific answers . I got other solution from here

推荐答案

.select()与检索实际选择的文本无关. Select就像.click()一样:将处理程序函数绑定到select事件的简便快捷方式.

.select() has nothing to do with retrieving the actual selected text. Select is just like .click(): an easy, shorthand way way to bind a handler function to the select event.

它在 API文档中正确显示:

检索当前所选文本的方法因浏览器而异.许多jQuery插件提供了跨平台的解决方案.

The method for retrieving the current selected text differs from one browser to another. A number of jQuery plug-ins offer cross-platform solutions.

因此,您绑定了element.select(...)(或者更好的是,element.on("select", ...)),然后使用许多跨平台解决方案之一来检索选择.这是基本思想: http://jsfiddle.net/NjW5a/3/

So you bind with element.select(...) (or better still, element.on("select", ...)), and then you use one of the many cross-platform solutions to retrieve the selection. This is the basic idea: http://jsfiddle.net/NjW5a/3/

这篇关于使用jquery .select()获得突出显示的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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