Home >Web Front-end >JS Tutorial >Js carriage return and line feed processing methods and application of replace method_javascript skills

Js carriage return and line feed processing methods and application of replace method_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:42:541437browse

When we enter text in the text box and press Enter, we hope that the web page will also display a line break effect after submission. At this time, we need to process the submitted content

to achieve the effect.
1. Define js native replacement function . There is no replaceAll function in js, we need to customize

Copy code 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
Copy code The code is as follows:

str= str.replaceAll("n", "
")

In this way, you can achieve the effect of js carriage return and line feed!
Statement:
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