Tag: all预览模式: 普通 | 列表
09-07
08

JavaScript 中的replace方法,正则或字符串全部交替

第一次发现javascript中replace() 方法如果直接用str.replace("-","!") 只会替换第一个匹配的字符.

引用内容 引用内容
replace()
The replace() method returns the string that results when you replace text matching its first argument
    (a regular e­xpression) with the text of the second argument (a string).
    If the g (global) flag is not set in the regular e­xpression 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);

查看更多...

Tags: JS replace all 正则

分类:Ajax/Js | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 322