在获取一个textarea光标位置 [英] Getting cursor position in a Textarea
问题描述
我想实现自动完成在文本区域(类似<一个href=\"http://www.pengoworks.com/workshop/jquery/autocomplete.htm\">http://www.pengoworks.com/workshop/jquery/autocomplete.htm).
I am trying to implement Autocomplete in a text area (similar to http://www.pengoworks.com/workshop/jquery/autocomplete.htm).
我所试图做的,当用户进入一个特定的字符集是(比如插入:)他们将获得与可能的选择匹配的AJAX充满DIV。
What I am trying to do is when a user enters a specific set of characters (say insert:) they will get an AJAX filled div with possible selectable matches.
在一个普通的文本框,这是当然简单,但在文本区域,我需要能够弹出股利的基础上光标在屏幕上的正确位置。
In a regular text box, this is of course simple, but in a text area I need to be able to popup the div in the correct location on the screen based on the cursor.
任何人都可以提供任何方向?
Can anyone provide any direction?
谢谢,
-M
Thanks, -M
推荐答案
您可以使用document.selection.createRange()插入符号,然后再研究它揭示你需要(如位置)的所有信息。请参见那些的范例了解更多详情。
You can get the caret using document.selection.createRange(), and then examining it to reveal all the information you need (such as position). See those examples for more details.
这篇关于在获取一个textarea光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!