最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Is there a way to get the insertion point in a textbox from javascript? - Stack Overflow

programmeradmin4浏览0评论

I'm trying to insert text into an html textbox when the user pushes buttons. This is a simple on screen numeric keypad. I have found many different scripts claiming to be able to find the current cursor position in a textbox cross-browser, but none work in IE (I'm using IE8). Is this just an IE8 defect? Is there a workaround?

It seems like there must be a definitive answer about this somewhere, but I have looked far and wide to no avail. To reiterate, how do I find the current cursor position in an html textbox?

I'm trying to insert text into an html textbox when the user pushes buttons. This is a simple on screen numeric keypad. I have found many different scripts claiming to be able to find the current cursor position in a textbox cross-browser, but none work in IE (I'm using IE8). Is this just an IE8 defect? Is there a workaround?

It seems like there must be a definitive answer about this somewhere, but I have looked far and wide to no avail. To reiterate, how do I find the current cursor position in an html textbox?

Share Improve this question asked Aug 17, 2009 at 17:59 PetePete 1,8102 gold badges20 silver badges31 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 12

look here:

http://javascript.nwbox./cursor_position/

Pete, you can also save the caret position by using an "onblur" event so you always know the previous caret position.

The link in the selected answer is no longer working. I found out you need to use field.selectionStart.

Please check out this answer: https://stackoverflow./a/48150864/4031815

发布评论

评论列表(0)

  1. 暂无评论