Home > Web Front-end > JS Tutorial > body text

Solution to the problem that the content submitted by textarea cannot be wrapped_Basic knowledge

WBOY
Release: 2016-05-16 17:37:59
Original
1043 people have browsed it

When we submit data through textarea on the page, the content we enter will be processed into a piece of content after submission. Even if we enter a lot of line breaks in the textarea, it will still be a piece of content after submission. So if we What should we do if we need to save the information we entered in the form we entered?

A major problem here is that when the page is displayed, the newline character is the
tag, and when the content is displayed in the textarea, the newline character is n. Here is a method to use js to input Line breaks in the content are converted to line breaks in the web page. Submit the money on the web page data and do the following processing.

Copy code The code is as follows:


also needs to be processed when displayed on the page, which is exactly the opposite of the above process:

Copy code The code is as follows :

content=content.replace('
','n');

The following is an explanation of the replace function of js:

Syntax:

stringObject.replace(regexp/substr,replacement)

The

replace() method is used to replace some characters with other characters in a string, or replace a substring that matches a regular expression.

1. Replace a single character

Copy the code The code is as follows:


2. Replace all specified characters present in the string (replace all)

Copy code The code is as follows:


The above /g is a regular expression, which shows that regular expressions can also be used in replace().

Of course there are more advanced usages of replace. You can get more advanced usages in the relevant documents.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!