我可以从文本或textarea之外的文本选择中获取Javascript事件吗? [英] Can I get a Javascript event from the selection of text outside of text or textarea?
问题描述
我想知道用户何时使用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.
- What's the event fired when a user selects text on a page?
- Javascript to get Paragraph of Selected Text in WebPage
这篇关于我可以从文本或textarea之外的文本选择中获取Javascript事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!