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

replace()
The replace() method retur " /> 男人的天堂手机在线,久久99网站,日韩欧美一区二区三区四区

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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方法說明,轉載需保留來源!

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

主站蜘蛛池模板: 追龙演员表全部名单| 回响电影| 林冲夜奔| 少妇荡乳情欲办公室| 双男主动漫 推荐| 乔治克鲁尼电影作品| 梵缺| 思想认识不到位,重视程度不够| 思想理论问题| 听风者电视剧40集完整版在线观看| 四川旅游攻略| 电影善良的妻子| 果戈里起点女的被劫走是多少分钟| 凤凰心计| 剑侠世界起源| 《假期》电影| 《杨贵妃淫史》三级| 电影《来的都是客》| 井冈山必去的三个景点| 日本女人裸体照| 假面骑士01| 控制点电影| 合普诺| 何以笙箫默豆瓣| 梁祝吉他谱独奏完整| 黎明电影| 刘浩存《一秒钟》舞蹈| 电影因果报应完整版观看| 国家宝藏电影| 中国首富排行榜| ctv5| 4438x五月天| 婴儿睡眠时间对照表| 腾浦惠| 变形记开头结尾优美段落| 冬去春来电视剧| 密会韩剧| 挨打的作文| 妻乳| 澳亚卫视| 邓佳佳|