chr*_*der 5 html javascript contenteditable
我创建了一个contentEditable编辑器,我需要获取光标的像素位置,以便我可以通过它定位菜单.(当用户键入特殊字符串时,菜单会自动打开以显示提示).
除了我不知道如何获得光标的实际像素位置以定位菜单之外,我已经完成了所有工作.我能做的最好的事情是获取光标所在的当前节点,但我仍然不知道光标在这个元素的"内".
? I can get the position of this div easily enough
<div>I am typing a message |</div>
? But I need the position of the cursor here
Run Code Online (Sandbox Code Playgroud)
编辑:我可以确认使用范围就像在textarea中一样也适用于ContentEditable.