How do I insert a character at the caret with javascript?

前端 未结 6 998
-上瘾入骨i
-上瘾入骨i 2021-01-02 05:55

I want to insert some special characters at the caret inside textboxes using javascript on a button. How can this be done?

The script needs to find the active textbo

6条回答
  •  半阙折子戏
    2021-01-02 06:47

    I'm not sure if you can capture the caret position, but if you can, you can avoid Jason Cohen's concern by capturing the location (in relation to the string) using the text box's onblur event.

提交回复
热议问题