Stop cursor from jumping to end of input field in javascript replace

后端 未结 3 969
盖世英雄少女心
盖世英雄少女心 2020-11-27 05:29

I\'m using a regular expression to strip invalid characters out of an text input area in javascript (running in IE). I run the replace function on every keyup event. However

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 06:08

    You'll have to manually put the cursor back where you want it. For IE9, set .selectionStart and .selectionEnd (or use .setSelectionRange(start, end)). For IE8 and earlier, use .createTextRange() and call .moveStart() on the text range.

提交回复
热议问题