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

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

WBOY
Release: 2016-05-16 17:42:54
Original
1380 people have browsed it

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!
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!