您可以使用闭包(通过自执行函数)来捕获
i每次循环调用的值,如下所示:
for (var i in obj) { (function(index) { // you can use the variable "index" here instead of i $.ajax(/script/).done(function(data){ console.log(data); }); })(i);}
您可以使用闭包(通过自执行函数)来捕获
i每次循环调用的值,如下所示:
for (var i in obj) { (function(index) { // you can use the variable "index" here instead of i $.ajax(/script/).done(function(data){ console.log(data); }); })(i);}