简体   繁体   中英

How to add text to a textarea with jquery or javascript

Basically the function will be similar to the "quote" function on most forums. I need to click a button to grab some text and paste that into a textarea box.

I've tried some things and they work, however, they don't work with everything. For example, they don't work when the text that I need to grab has white spaces or apostrophes or if the text is very long. Any help?

I've tried most of the solutions outlined in this thread: Insert text into textarea with jQuery and they do not work.

var element = $('#idofyourdomelement');
element.val(element.val() + ' foo bar added');

And live demo as always.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM