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

前端 未结 6 957
-上瘾入骨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:43

    loop over all you input fields... finding the one that has focus.. then once you have your text area... you should be able to do something like...

    myTextArea.value = 'text to insert in the text area goes here';

提交回复
热议问题