开发者

array item losing value when input checked

开发者 https://www.devze.com 2023-01-26 01:38 出处:网络
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\"?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消