The problem of variables returned in the jQuery each function! External call!
The current demand is to judge whether the number of changes in the exchanged goods is all 0. If all are 0, a prompt box needs to be popped up and submitted!
javascript:
// Iterate the number of changes in the product, if all are 0, it will not be submitted
var sub = 0;
$(“.goods_number”).each(function () {
if (sub == 0) {
if ($(this).val() != 0) {
// var sub == 1;
return (sub = 1);
// return false;
} else {
return true;
}
} else {
return false;
}
})
if (sub == 0) {
alert(The number of changes in the exchange of goods cannot be all 0);
return false;
}
It is found that the assignment of variables within the function cannot be passed in the follow-up, and it needs to be returned, and it can return multiple values!
The only problem now is that even if it is judged that the value of a change is not 0, it will continue to loop once, otherwise the value of the SUB cannot be used in the subsequent judgment!
