最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript 中的replace方法說明

 更新時(shí)間:2007年04月13日 00:00:00   作者:  
第一次發(fā)現(xiàn)JavaScript中replace() 方法如果直接用str.replace("-","!") 只會(huì)替換第一個(gè)匹配的字符.  
而str.replace(/\-/g,"!")則可以替換掉全部匹配的字符(g為全局標(biāo)志)。  

replace()  
The replace() method returns the string that results when you replace text matching its first argument  
(a regular expression) with the text of the second argument (a string).  
If the g (global) flag is not set in the regular expression declaration, this method replaces only the first  
occurrence of the pattern. For example,  

var s = "Hello. Regexps are fun.";s = s.replace(/\./, "!"); // replace first period with an exclamation pointalert(s); 

produces the string “Hello! Regexps are fun.” Including the g flag will cause the interpreter to  
perform a global replace, finding and replacing every matching substring. For example,  

var s = "Hello. Regexps are fun.";s = s.replace(/\./g, "!"); // replace all periods with exclamation pointsalert(s); 

yields this result: “Hello! Regexps are fun!”  

相關(guān)文章

最新評(píng)論

临猗县| 鹤岗市| 从化市| 嘉禾县| 神农架林区| 乐东| 汝州市| 刚察县| 蓬莱市| 曲沃县| 吉安市| 渭南市| 民乐县| 桐庐县| 错那县| 昭觉县| 千阳县| 朝阳县| 青田县| 沾益县| 秦安县| 蓝田县| 佛教| 黔南| 富平县| 丰顺县| 湖南省| 重庆市| 应城市| 阜南县| 桓仁| 融水| 静宁县| 琼海市| 临海市| 吴旗县| 九寨沟县| 勃利县| 高尔夫| 揭东县| 沙河市|