开发者

Insert text in textarea at caret position [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜