我已经添加了一个按键委托(delegate)事件,但没有获得事件的坐标。
我需要坐标通过更改 top 和 left 属性的 css 在光标位置显示自动建议列表。
<div class="dropdown suggest open" data-key="." css="display: ${autoSuggestTool.display}">
<ul class="dropdown-menu" role="menu" css="top:${autoSuggestTool.top}; left: ${autoSuggestTool.left};">
<li data-value="Test" class="active "><a href="#"><small>Test</small></a></li> </ul>
</div>
<textarea class="form-control" rows="5" cols="6" id="comment" value.bind="textAreaValue" keypress.delegate="autoSuggest($event)" placeholder="Type text "></textarea>
//.ts文件中的代码:
autosuggest(event){
//here i need the pageX and PageY or offset to set the postion
//this.autoSuggestTool.left = event.pageX;
//this.autoSuggestTool.top= event.pageY;
//**But in event i am not getting the co-ordinate of cursor inside textarea**
//How to get the co-ordinate of cursor on key press in aurelia.
}
最佳答案
因为你委托(delegate)的是keypress
,你接触到的是一个KeyboardEvent
类型的事件,因此里面没有坐标信息。
但是委派给click
、mousedown
等(键入MouseEvent
),您应该能够看到pageX、clientX 等。
关于javascript - 在 Aurelia 中,如何根据按键事件获取文本区域内光标的坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46010869/