最高半折刷qq各种业务和钻(家里人自己开的,尽管放心,大家多捧捧场)

sking7

导航

Replace回调函数参数的使用

var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';
function f(s, width){
var a=new RegExp('[\\s\\S]{1,'+(width || 4)+'}', 'g');
return s.replace(
a,
function(K,M,L,N){
console.log('==='+K);//第一个参数:匹配项
console.log('---'+M);//第一个参数:匹配项的起始index
console.log('---'+L);//整个字符串
console.log('---'+N);//undefined
return '^' + new Array(K.length).join(' ');
});
}
console.log(f(s, 4));



posted on 2011-10-26 11:09  G.N&K  阅读(457)  评论(0编辑  收藏  举报