开发者

Insert text in textarea at caret position [duplicate]

开发者 https://www.devze.com 2023-04-09 08:59 出处:网络
This question already has an answer开发者_Go百科 here: Closed 11 years ago. Possible Duplicate: How to insert text at the current caret position in a textarea
This question already has an answer开发者_Go百科 here: Closed 11 years ago.

Possible Duplicate:

How to insert text at the current caret position in a textarea

I want to insert text in a textarea using javascript at the caret position, i already have the code to find the position, whats the code to put text at that particular position?

Thanks,

Jake


var myTextarea = ... // select the text area
$(myTextarea).html('The text I want to insert'); // this will replace the existing contents

To append text to the textarea, use this:

$(myTextarea).html($(myTextarea.html() + 'The text I want to insert');
0

精彩评论

暂无评论...
验证码 换一张
取 消