This article mainly introduces the relevant knowledge of the simple rollback operation of each loop in jquery, which has a good reference value. Let's take a look with the editor below, I hope it can help everyone.
Without further ado, please take a look at the code:
var ispass = true; var obj = new Object(); $.each(data,function(i,td){ var sum=data[i].sum; var num=data[i].num; var id=data[i].num; if(num>sum){ ispass=false; alert("数量不能大于总数量!"); sum+=num; return false; } obj[id]=sum; }) if(!ispass){ return false;//如果执行到这里则上面的each循环的内容都不存在 }else{ $.each(obj,function(id,sum){ alert(id); alert(num); }) }
Related recommendations:
What is the difference between for and foreach loop traversal in PHP
foreach loop usage example code
JQuery jumps out of each loop example code sharing
The above is the detailed content of Example sharing of simple rollback operation of each loop in jquery. For more information, please follow other related articles on the PHP Chinese website!