返回

js replaceAll

js 全部替换:

/**
* 替换(所有)
* @param str 要处理的字符串
* @param beRepStr 被替换的字符串
* @param toRepStr 最终生成的字符串
* @returns {string}
*/
function myReplace(str,beRepStr,toRepStr){
var result = '';
function replaceAll(str,beRepStr,toRepStr){
if(str.indexOf(beRepStr)!=-1){
replaceAll(str.replace(beRepStr,toRepStr),beRepStr,toRepStr);
}else{
result = str;
}
}
replaceAll(str,beRepStr,toRepStr);
return result;
}
posted @ 2016-10-12 10:20  feige_hunter  阅读(375)  评论(0编辑  收藏  举报