【发布时间】:2019-05-09 06:00:31
【问题描述】:
在 keydown 事件中,我无法确定新插入字符的位置。 反正有知道位置吗?
【问题讨论】:
-
console.log(event.selectionStart)? -
为任何偶然发现此问题的人发布答案!请接受:)
在 keydown 事件中,我无法确定新插入字符的位置。 反正有知道位置吗?
【问题讨论】:
console.log(event.selectionStart) ?
要知道光标在 keydown/keyup 事件上的位置,我们需要 selectionStart from $event
yourEvent(event) {
const characterPosition = event.selectionStart;
console.log('The cursor position on keydown is:', characterPosition);
}
【讨论】: