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

Implementation method of replacing all strings in jQuery

小云云
Release: 2018-01-23 09:09:15
Original
2684 people have browsed it

How much do you know about jQuery string replacement? This article mainly introduces jQuery's method of replacing all strings, which has a good reference value. Let's take a look with the editor below, I hope it can help everyone.

Everyone knows that jquery has a replace method that can replace "" in a string with any character, but it can only replace one place. If there are multiple places, you can only use regular expressions. The last code to process


var title = "aaa aaa aaa";
var re = new RegExp(" ","g"); //定义正则表达式
//第一个参数是要替换掉的内容,第二个参数"g"表示替换全部(global)。
newTitle = title!=null?title.replace(re, "_"):title;
//三目运算
Copy after login

is to replace " " with _

according to the re regular expression rules. In addition, there are regular testing tools on the front-end website. Recently, I also Let’s continue to learn regular rules, let’s work together! ! !

Related recommendations:

Introduction to how to use the php string replacement str_replace() function

How to use the JavaScript replace string replacement function

js replace php function substring replacement str_replace


The above is the detailed content of Implementation method of replacing all strings in jQuery. For more information, please follow other related articles on the PHP Chinese website!

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!