where syntax error goes in my javascript code?
If I run this code in Firebug everything goes fin开发者_如何学Pythone and works:
var ingarray =$(".ingsparts");
$.each(ingarray ,function(n){
var ing = ingarray[n];
console.log($(ing).find('.name').val());
console.log($(ing).find('.value').val())
});
but if I run this, it doesn't work:
var ingarray =$(".ingsparts");
$.each(ingarray ,function(n){
var ing = ingarray[n];
var in = $(ing).find('.name').val();
var ms = $(ing).find('.value').val();
});
It seems that in
is a reserved word; use another variable name.
in
is a reserved word in Javascript (see here for more info), you will have to rename this variable.
Yeah, dont use in as variable name, but also, your each can be done more simply:
var ingarray = $(".ingsparts");
ingarray.each(function(){
var name = $(this).find('.name').val();
var value = $(this).find('.value').val();
...
});
The second example defines the in and ms variables inside the function. This means that they get function scope and are not usable outside of the function. So the variables are set, but never used and not accessed.
精彩评论