Working with textarea spaces and wrapping lines

Source: Internet
Author: User

Just sent a blog, then found that csdn in the publishing user's article seems not to handle the input line and space, not very concerned about, because this time I worked hard to indent the code actually shows a mess, a bit unacceptable, in view of the recent need to meet this problem, so say this question, Given that development is under Windows, Linux and Apple are free to test again because different operating systems differ in their presentation.

In fact, this process is very simple, with a code can be solved, "your string". Replace (/\n/g, "<br/>"). Replace (/\s/g, "&nbsp;"), line wrap is usually \r,\n or \ r \ n , just different systems are not the same, we are interested to try. The principle is that textarea will insert the user button into the string, but in the browser, the <br/>,&nbsp that represents the line break and the space, so we need to turn to the browser character before rendering.

Incidentally, you can implement a simple textarea by H5 's property contenteditalble, but this is the input line and the space will be converted into a browser corresponding format, again show when we do not need to turn, but this property to implement the text box will have a lot of thorny problems, Interested to have a look.

Related Article

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.