插入符号以像素为单位 [英] Caret coordinates in pixels

查看:86
本文介绍了插入符号以像素为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要计算TEXTAREA中的插入符号坐标(以像素为单位)。

指出我正确的方向将不胜感激。

谢谢

MaxIRMX

Hi everybody,
I need to calculate caret coordinates within TEXTAREA in pixels.
Pointing me to the right direction will be appreciated.
Thanks
MaxIRMX

推荐答案

这两个链接应该有所帮助:
http:// www .quirksmode.org / js / findpos.html
http://www.quirksmode.org/dom/tests/offset.html
These two links should help:
http://www.quirksmode.org/js/findpos.html
http://www.quirksmode.org/dom/tests/offset.html



这两个链接应该是帮助:
http://www.quirksmode.org/js/ findpos.html
http:// www .quirksmode.org / dom / tests / offset.html



对不起,它没有。我理解如何计算对象坐标。但是,任务是在textarea中找到CARET坐标。看起来创建一个范围可能适用于IE但我找不到任何适用于Firefox的东西。

Sorry, it does not. I understand how to calculate object coordinates. However, the task is to find CARET coordinates within textarea. It looks like creating a range might work for IE but I could not find anything that worked for Firefox.



任务是找到CARET textarea内的坐标。
the task is to find CARET coordinates within textarea.



这是一个范围,但您可以尝试从相关的textarea元素中捕获onChange事件,并检查事件的坐标。我不确定它是否会返回胡萝卜或鼠标光标的位置。


如果它确实返回了胡萝卜的位置,它可能是页面上的位置而不是textarea内部的位置。您可以通过从TextArea元素的位置减去X,Y值来获取文本区域中的位置。不同的应该是textarea内的位置。

This is a reach, but you might try catching the onChange event from the textarea element in question, and checking the coordinates from the event. I am not sure if it would return the location of the carrot, or the mouse cursor.

If it does return the position of the carrot it would probably be the position on the page not the position inside the textarea. You could get the position in the text area though by subtracting the X, Y values from the position of the TextArea elment. The different should be the position inside the textarea.


这篇关于插入符号以像素为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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