在插入位置的textarea中插入文本

时间:2011-09-30 15:06:51

标签: javascript jquery

  

可能重复:
  How to insert text at the current caret position in a textarea

我想在插入位置使用javascript在textarea中插入文本,我已经有代码来查找位置,是什么代码将文本放在特定位置?

谢谢,

杰克

1 个答案:

答案 0 :(得分:0)

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

要将文本附加到textarea,请使用:

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