gpt4 book ai didi

javascript - 光标前面的字符

转载 作者:行者123 更新时间:2023-12-02 19:56:11 25 4
gpt4 key购买 nike

是否可以使用 keydown 事件将索引检索到光标所在的文本区域?

最佳答案

是的,确实如此。

<小时/>
textarea.addEventListener('keydown', function (){
console.log(textarea.selectionEnd); //The position of the cursor. If something is selected, then the position of the end of the selection.
}, false);

此功能不适用于 IE。在 IE 中,您必须使用 document.createTextRange()

关于javascript - 光标前面的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8607837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com