JS Replace 全部替换字符用法
来源:互联网 发布:足球指数分析软件 编辑:程序博客网 时间:2024/05/21 19:48
之前在做一个项目的时候,理应出现的是html中的<p>111</p><p>222</p><p>333</p>,但是看到的却是下面这些
被转义为: & lt ;p& gt ; 111& lt ;/p& gt ; & lt ;p& gt ; 222& lt ;/p& gt ; & lt ;p& gt ; 333& lt ;/p& gt ;
< : & lt ;
> :& gt ;
& :& amp ;
str.replace(/</g, "<")
replace方法中第一个/是转义, /g标识全文匹配
这里我们要说的就是怎么把其转义回来,用到的是下面这个方法:
JavaScript replace() 方法
http://www.w3school.com.cn/jsref/jsref_replace.asp其中例子2中就解释的很好,同样我们执行这个方法也可以实现我们想要的效果
在本例中,我们将执行一次全局替换,每当 "Microsoft" 被找到,它就被替换为 "W3School":
<script type="text/javascript">var str="Welcome to Microsoft! "str=str + "We are proud to announce that Microsoft has "str=str + "one of the largest Web Developers sites in the world."document.write(str.replace(/Microsoft/g, "W3School")
)</script>
输出:
Welcome to W3School! We are proud to announce that W3Schoolhas one of the largest Web Developers sites in the world.
0 0
- JS Replace 全部替换字符 用法
- JS Replace 全部替换字符 用法
- JS Replace 全部替换字符 用法
- JS Replace 全部替换字符用法
- jS Replace 全部替换字符 用法
- JS Replace 全部替换字符 用法
- JS Replace 全部替换字符
- JS Replace全部替换字符方法
- js replace 全部替换
- js replace 替换全部
- js replace 全部替换字符串
- Jquery,JS全部替换replace
- jquery 将某个字符全部替换 replace
- JS 字符串全部替换 ,replace (/ /g,'')
- JS RegExp和replace全部替换
- js中 replace() 全部替换实例
- js 全部替换replace() 使用正则表达式
- js中 replace replaceAll 全部替换
- php解压zip文件
- Unity3D中的svn上传目录
- 简单的概率问题
- Android Studio打开出错,Internal Error......failed to create a child event loop......
- 栈的一些基本操作
- JS Replace 全部替换字符用法
- 归并排序
- iOS 开发中的一些小问题和技巧
- LeetCode#338. Counting Bits
- PowerDesigner中NAME和COMMENT的互相转换,需要执行语句
- 166.View the Exhibit and examine the structures of the EMPLOYEES and DEPARTMENTS tables.
- 英语口语444
- Java千百问_02基本使用(005)_Mac环境下无法打开eclipse怎么办
- 编写select下拉框的几种方式