Home > Article > Web Front-end > Solution to the problem that the content submitted by textarea cannot be wrapped_Basic knowledge
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.
also needs to be processed when displayed on the page, which is exactly the opposite of the above process:
The following is an explanation of the replace function of js:
Syntax:
stringObject.replace(regexp/substr,replacement)
Thereplace() 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
2. Replace all specified characters present in the string (replace all)
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.