当前位置: 首页 > 图文教程 > 网页制作 > HTML/XHTML教程 > JavaScript 中的replace方法

HTML/XHTML教程
精通 CSS 滤镜(一)
精通 CSS 滤镜(二)
CSS入门
网站首页head区代码规范
CSS2盒模型的3D示意图
增强网站的可访问性
利用CSS,链接下划线也玩自定义
网页留白的艺术
网页色彩搭配的内涵
巧用CSS制作树状目录
巧用CSS的Border属性制作特效菜单
巧用CSS制作图象特效
巧用CSS制作文字变图象特效
target=_blank不符合标准?
让自己的网站也拥有权威IT报价系统
弹出网页窗口设计全攻略
CSS 循序渐进(四)表里春秋(上)
CSS实用教程(三)
CSS 循序渐进(四)表里春秋(下)
CSS实用教程(一)

HTML/XHTML教程 中的 JavaScript 中的replace方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-04   浏览: 68 ::
收藏到网摘: n/a

1第一次发现JavaScript中replace() 方法如果直接用str.replace("-","!") 只会替换第一个匹配的字符. 
 2而str.replace(/\-/g,"!")则可以替换掉全部匹配的字符(g为全局标志)。
 3
 4
 5replace() 
 6The replace() method returns the string that results when you replace text matching its first argument 
 7(a regular expression) with the text of the second argument (a string). 
 8If the g (global) flag is not set in the regular expression declaration, this method replaces only the first 
 9occurrence of the pattern. For example, 
10
11var s = "Hello. Regexps are fun.";s = s.replace(