JS replace 回调

JS中 字符串的replace函数 可以接受回调函数 

例如 
一般用法:
var a = '1,2,3,4,5';
var b = a.replace('2,3','*');
console.log(b);  
输出:'1,*,4,5'

回调函数的用法:
var a = '1,2,3,4,5';
var b = a.replace( '2,3' ,function(match){
        return '*';
 
});
console.log(b);
输出:'1,*,4,5'
posted on 2013-04-27 13:48  花森  阅读(286)  评论(0编辑  收藏  举报