简体   繁体   中英

jQuery: Inserting formatted text into a textarea

I have a drop-down list which causes a text-area to populate with different text depending on what's selected. I have this part working fine, but I'm not able to format the text to show paragraphs. using regular html, just causes it to be printed out.

Does any one know can I create paragraphs, etc?

Thanks Guys!!

You'll need to use some sort of rich text editor, like CKEditor , or, use newlines \\n . The <p> will be interpreted literally in a textarea .

<p> is an HTML tag. <textarea> doesn't recognize HTML tags, unless you're using some kind of rich-text editor.

That said, you can create line breaks in your <textarea> using \\n like this:

$('#my-text-area').text('foo\nbar');

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