而str.replace(//-/g,"!")則可以替換掉全部匹配的字符(g為全局標志)。

replace()
The replace() method retur " /> 久久精品国产久精国产爱,91色在线看,国产精品久久777777毛茸茸

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

JavaScript 中的replace方法說明

第一次發現JavaScript中replace() 方法如果直接用str.replace("-","!") 只會替換第一個匹配的字符.  
而str.replace(//-/g,"!")則可以替換掉全部匹配的字符(g為全局標志)。  

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!”  

JavaScript技術JavaScript 中的replace方法說明,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 扎鲁特旗| 长春市| 连州市| 浦县| 琼海市| 东平县| 三门峡市| 凤冈县| 根河市| 湾仔区| 报价| 镇远县| 虎林市| 乐亭县| 洪雅县| 安化县| 河北区| 岫岩| 道孚县| 苏州市| 咸阳市| 吉林省| 呈贡县| 阿克陶县| 瑞丽市| 巫溪县| 中西区| 迁安市| 英超| 肥西县| 左权县| 河西区| 琼结县| 龙里县| 兴国县| 柳林县| 德昌县| 涿鹿县| 修武县| 银川市| 阳城县|