jquery 遍历 对象数组 问题
JScript code
var ddd = new Array();
for (var i = 0; i < 10; i++) {
var aaa = new Object();
aaa.id = 'id_' + i;
aaa.val = 0;
ddd.push(item);
}
$.each(ddd, function(index, obj) {
if (obj.id == 'id_7');
{
obj.val = 10;
}
alert(obj.val);
});
办出应该只有一个10,但是现在输出都是10,是什么原因?
------解决方案--------------------
var ddd = new Array();
for (var i = 0; i < 10; i++) {
var aaa = new Object();
aaa.id = 'id_' + i;
aaa.val = 0;
ddd.push(aaa);
}
$.each(ddd, function(index, obj) {
if (obj.id == 'id_7'); { //这里多了个分号
obj.val = 10;
}
alert(obj.val);
});