请将All over the world people enjoy sports替换成All1 over2 the3 world4 people5 enjoy6 sports7
大牛的实现:
var i = 0, str = "All over the world people enjoy sports";
str = str.replace(/\S+/g, function($){return $ + [++i]});
alert(str);
请将All over the world people enjoy sports替换成All1 over2 the3 world4 people5 enjoy6 sports7
大牛的实现:
var i = 0, str = "All over the world people enjoy sports";
str = str.replace(/\S+/g, function($){return $ + [++i]});
alert(str);
转载于:https://www.cnblogs.com/kfx2007/archive/2012/04/12/2444237.html