关于 js replace function 参数的问题
var arr = ['a','b','c','d'];
var t = "<img src='' id='good'><img src='' id='man'><img src='' id='is'><img src='' id='u'>";
t = t.replace(/id='(\w*)'/g,function(match,$1,index){
console.log(match,$1,index);
//id='good' good 12
//id='man' man 34
//id='is' is 55
//id='u' u 75
return "id='"+ arr[$1-1]+"'";
})
match $1 都理解了 这个index 是什么意思 求指教
相关分类