javascript - 关于 js replace function 参数的问题
本文介绍了javascript - 关于 js replace function 参数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
关于 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 是什么意思 求指教
解决方案
https://developer.mozilla.org...
你可以看这个
index应该对应着这里说的offset
这篇关于javascript - 关于 js replace function 参数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文