array item losing value when input checked
Why is it that I get the proper value of "item" in the first loop, but in the each loop I get undefined? How do I keep the value of the "item"?
Here's the code:
for (item in products_custom)开发者_JAVA技巧{
console.log(item);
$("input:checked").each(function(){
console.log(item);
});
}
Thanks a lot for your help.
You're not closing your each
call properly, so if that were your real code, it would give a syntax error. It should be:
for (var item in products_custom){
console.log(item);
$("input:checked").each(function(){
console.log(item);
});
}
Note we use var
to avoid a global. However, neither of these issues fit with the problem you describe, and it works (jsFiddle) after fixing the syntax errors.
精彩评论