jquery replacement method for line wrapping in textarea

Source: Internet
Author: User
Tags html tags

Yesterday when colleagues were learning jquery, they wanted to use the swap line in the textarea.

HTML section:

1 2 3 4 <fieldset> <textarea id= "ncontent" ></textarea> </fieldset> <button id= "Submit" > Submit < /button>

JS section:

1 2 3 4 5 6 7 8 9 $ (document). Ready (function () {$ ("#submit"). Click (function () {var SS = $ ("#ncontent"). Text (); alert (ss); var str = Ss.replace (//R/N/GI, "!!!"); alert (str); }); }); </script>

After using the Replace () method of JavaScript, the newline is still not replaced.

The problem is getting the value in jquery to get textarea. should use

Copy code code as follows: var SS = $ ("#ncontent"). html ();

Using the text () or Val () method, the HTML tags in the textarea are processed, so it's definitely not a/r/n.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.