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

jQuery replace string (example code)_jquery

WBOY
Release: 2016-05-16 17:15:56
Original
1166 people have browsed it

Copy code The code is as follows:

function replace()
{
var str="tao zhang yi love liu weng ling";
re=new RegExp("l","g");
var newstart=str.replace(re,"t");
alert (newstr);
}

Running result: "tao zhang yi tove tiu weng ting" pops up;

Explanation: re=new RegExp("l","g") The first parameter is the string you want to replace, and the second parameter refers to the replacement All of them, the second parameter can also be set to ("i"), which means only the first string is replaced.

The second parameter in str.replace(re, "t") is the string you want to modify.

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