When we enter text in the text box and press enter, we hope that after the submission, the web page will also display the effect of line breaks, which often cannot be fulfilled, I am so angry that I wrote a function for handling line breaks by carriage return. If you are interested, I hope this article will help you. When we enter text in the text box and press enter, we hope that after the submission, the web page will also display a line feed effect. At this time, we need to process the submitted content.
To achieve the effect.
1. Define native replacement functions of js. Js does not have the replaceAll function. We need to customize it.
The Code is as follows:
String. prototype. replaceAll = function (s1, s2 ){
Return this. replace (new RegExp (s1, "gm"), s2 );
}
2. Use js replace for processing
The Code is as follows:
Str = str. replaceAll ("\ n ","
")
In this way, we can achieve the effect of js carriage return and line feed!