【www.gdgbn.com--网页配色】

利用网页特效  str.replace(/-/g,"!")则可以全部替换掉匹配的字符(g为全局标志)。

<script type="text/javascript">
  string.prototype.replaceall = function(reallydo, replacewith, ignorecase) {
  if (!regexp.prototype.isprototypeof(reallydo)) {
return this.replace(new regexp(reallydo, (ignorecase ? "gi": "g")), replacewith);
} else {
return this.replace(reallydo, replacewith);
}
}
</script>

string.replace(/reallydo/g, replacewith);
string.replace(new regexp(reallydo, "g"), replacewith);
string:字符串表达式包含要替代的子字符串。
reallydo:被搜索的子字符串。
replacewith:用于替换的子字符串。

本文来源:http://www.gdgbn.com/wangyezhizuo/28580/