We use continue in the for loop; the termination of this loop is counted in the next loop, and break is used to terminate the entire loop. The following editor will share with you the sample code for jumping out of the loop in JS through this article. Friends who need it can refer to it
1. We use continue in the for loop; terminating this loop will be counted as the next loop, and use break to terminate The whole cycle.
2. In jquery, $.each uses return true to terminate this cycle and count it into the next cycle, and return false to terminate the entire cycle. The function return value has nothing to do with this.
Example:
$.extend($.fn.datagrid.methods, { isChecked: function (dg, param) { var flag = false;//是否选中 var allRows = $(dg).datagrid('getChecked'); //获取所有被选中的行 $.each(allRows, function (index,item) { if (param.rowIndex == $(dg).datagrid('getRowIndex', item)) { flag = true; return false;//return false终止循环,return true,跳出循环,进入下一次循环,跟函数返回值无关 } }) return flag; } })
The above is the detailed content of Jump out of loop code display in JS. For more information, please follow other related articles on the PHP Chinese website!