我可以从文本或textarea之外的文本选择中获取Javascript事件吗? [英] Can I get a Javascript event from the selection of text outside of text or textarea?

查看:91
本文介绍了我可以从文本或textarea之外的文本选择中获取Javascript事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道用户何时使用Javascript在html页面中选择文本。该文本不应该是可编辑的。 onselect 事件似乎仅适用于< textarea> <输入类型=TEXT> 标签。如果任一标签被禁用,则不会触发该事件。

I would like to know when a user selects text in an html page using Javascript. The text should not be editable. The onselect event seems to be only applicable to <textarea> and <input type="TEXT"> tags. The event is not fired if either tag is disabled.

这些标签有解决方法吗?

Is there a way around this with these tags?

有没有完全不同的方法?

Is there a completely different approach?

推荐答案

当然,这里有一个例子: http://www.codetoad.com/javascript_get_selected_text.asp

Sure, an example exists here: http://www.codetoad.com/javascript_get_selected_text.asp

使用什么你在这里看到,你可以将事件绑定到文档正文的单击/释放事件,并检查是否有选择,以及选择确定他们是否选择了任何文本的时间。

Using what you see here, you could bind events to the click/release events of the document body, and check to see if there is a selection, and how long the selection is to determine if they've selected any text.


  1. 当用户选择页面上的文字时,该事件是什么?

  2. Javascript获取网页中所选文本的段落

  1. What's the event fired when a user selects text on a page?
  2. Javascript to get Paragraph of Selected Text in WebPage

这篇关于我可以从文本或textarea之外的文本选择中获取Javascript事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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