<div class="codetitle"> <span><a style="CURSOR: pointer" data="74035" class="copybut" id="copybut74035" onclick="doCopy('code74035')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code74035"> <br>/** <br>* 替换字符串中所有 <br>* @param obj 原字符串 <br>* @param str1 替换规则 <br>* @param str2 替换成什么 <br>* @return 替换后的字符串 <br>*/ <br>function replaceAll(obj,str1,str2){ <br>var result = obj.replace(eval("/"+str1+"/gi"),str2); <br>return result; <br>} <br> </div> <br>例如: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="65749" class="copybut" id="copybut65749" onclick="doCopy('code65749')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code65749"> <br> <br> <br> <br><title> New Document </title> <br><meta name="Generator" content="EditPlus"> <br><meta name="Author" content=""> <br><meta name="Keywords" content=""> <br><meta name="Description" content=""> <br><script type="text/javascript"> <BR>function replaceAll(obj,str1,str2){ <BR>var result = obj.replace(eval("/"+str1+"/gi"),str2); <BR>return result; <BR>} <BR>alert(replaceAll("111,222,333",",","|")); <BR></script> <br> <br> <br> <br> <br> </div>