我在循环加载图片时遇到问题:
var m = ["http://localhost:801/grillduck/img/mark1.jpg", "http://localhost:801/grillduck/img/mark2.jpg"];
for (i = 0; i < m.length; i++) {
var img = $("<img />").attr('src', m[i]).load(function() {
console.log($(this).height());
console.log($(this).width());
console.log(i); // PROBLEM here always return 2 instead of 0 then 1
var content = $('<div class="ho-content" id="demo-content' + i + '">');
});
}
问题是我需要为循环获取正确的I值才能创建div,但它总是返回2.
Cheerio, 标记