Home > Web Front-end > JS Tutorial > body text

Jump out of loop code display in JS

巴扎黑
Release: 2017-09-16 09:53:10
Original
1360 people have browsed it

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;
   }
 })
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!