如何将文字附加到'< textarea>'?
我有< textarea>
用户可以在这里向世界输入他的信息!下面,有上传按钮...我想添加上传文件的链接(不用担心,我有它);就在他输入的文本旁边。
I have <textarea>
where user can type in his message to the world! Below, there are upload buttons... I would love to add link to uploaded file (don't worry, I have it); right next to the text that he was typing in.
喜欢,他输入'Hello,world!',然后上传文件(通过AJAX完成),以及该文件的链接将添加到< textarea>
的内容的下一行。注意!是否可以将光标(他离开的地方)保存在同一个地方?
Like, he types in 'Hello, world!', then uploads the file (its done via AJAX), and the link to that file is added in next line to the content of <textarea>
. Attention! Is it possible to keep cursor (place where he left to type) in the same place?
所有可以用jQuery完成的任何想法?我知道有方法'append()',但它不适用于这种情况,对吗?
All that may be done with jQuery... Any ideas? I know that there are method 'append()', but it won't be for this situation, right?
尝试
var myTextArea = $('#myTextarea');
myTextArea.val(myTextArea.val() + '\nYour appended stuff');