JavaScript 中的replace方法說(shuō)明
而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)文章
JavaScript動(dòng)態(tài)修改彈出窗口大小的方法
這篇文章主要介紹了JavaScript動(dòng)態(tài)修改彈出窗口大小的方法,涉及javascript中window.open方法的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04javascript動(dòng)態(tài)分頁(yè)的實(shí)現(xiàn)方法實(shí)例
最近的項(xiàng)目需要添加一個(gè)分頁(yè)導(dǎo)航的功能,沒(méi)有用網(wǎng)上封裝好的文件,通過(guò)JS自己簡(jiǎn)單實(shí)現(xiàn)了效果,這篇文章主要給大家介紹了關(guān)于javascript動(dòng)態(tài)分頁(yè)的實(shí)現(xiàn)方法,需要的朋友可以參考下2022-06-06JS實(shí)現(xiàn)求數(shù)組起始項(xiàng)到終止項(xiàng)之和的方法【基于數(shù)組擴(kuò)展函數(shù)】
這篇文章主要介紹了JS實(shí)現(xiàn)求數(shù)組起始項(xiàng)到終止項(xiàng)之和的方法,基于數(shù)組擴(kuò)展函數(shù)實(shí)現(xiàn)該功能,涉及javascript針對(duì)數(shù)組的簡(jiǎn)單判斷、遍歷等相關(guān)操作技巧,需要的朋友可以參考下2017-06-06微信小程序?qū)崿F(xiàn)密碼顯示與隱藏的睜眼閉眼功能
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)密碼顯示與隱藏的睜眼閉眼功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-02-02ionic進(jìn)入多級(jí)目錄后隱藏底部導(dǎo)航欄(tabs)的完美解決方案
這篇文章主要介紹了ionic進(jìn)入多級(jí)目錄后隱藏底部導(dǎo)航欄(tabs)的完美解決方案,在文章中用到了angularjs的指令知識(shí)點(diǎn),對(duì)ionic隱藏底部導(dǎo)航欄知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-11-11javascript中alert()與console.log()的區(qū)別
我們?cè)谧鰆s調(diào)試的時(shí)候使用 alert 可以顯示信息,調(diào)試程序,alert 彈出窗口會(huì)中斷程序, 如果要在循環(huán)中顯示信息,手點(diǎn)擊關(guān)閉窗口都累死。而且 alert 顯示對(duì)象永遠(yuǎn)顯示為[object ]。 自己寫的 log 雖然可以顯示一些 object 信息,但很多功能支持都沒(méi)有 console 好2015-08-08JavaScript設(shè)計(jì)模式之構(gòu)造器模式(生成器模式)定義與用法實(shí)例分析
這篇文章主要介紹了JavaScript設(shè)計(jì)模式之構(gòu)造器模式(生成器模式)定義與用法,結(jié)合實(shí)例形式分析了javascript構(gòu)造器模式的概念、原理、與工廠模式的區(qū)別以及相關(guān)使用方法,需要的朋友可以參考下2018-07-07微信小程序?qū)崿F(xiàn)商品屬性聯(lián)動(dòng)選擇
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)商品屬性聯(lián)動(dòng)選擇,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02