如何将文本附加到“<textarea>"? [英] How to append text to '<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() + '
Your appended stuff');
这篇关于如何将文本附加到“<textarea>"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!