大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 网页设计 -> 网页特效 -> JavaScript 中的replace方法

JavaScript 中的replace方法

时间: 2021-07-31 作者:daque

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, 1011var s = "hello. regexps are fun.";s = s.replace(/\./, "!"); // replace first period with an exclamation pointalert(s); 1213produces the string “hello! regexps are fun.” including the g flag will cause the interpreter to 14perform a global replace, finding and replacing every matching substring. for example, 1516var s = "hello. regexps are fun.";s = s.replace(/\./g, "!"); // replace all periods with exclamation pointsalert(s); 1718yields this result: “hello! regexps are fun!” 

javascript 中的replace方法图1

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.