jQuery循环中的break和continue


在jQuery中循环页面中各个控件的操作用的很多,常用的循环操作如下:

// 循环页面上id为weiguo_开头的所有div标签

   $("div[id^=weiguo_]").each(function(index){

//获取div中的内容

        var iDValue=$(this).text();

         // 如果这次循环符合条件,马上跳出循环。

           if(iDValue==0){
               checkMark=false;
               blankTextArray.push(idval);
                //  break----用return false 语法来标识
                return false;

             }

    }

 

需要注意的地方

 在each代码块内不能使用break和continue,要实现break和continue的功能的话,要使用如下的方式:
break----用return false;
continue --用return ture;

所以在jquery循环中想返回false或 返回true ,操作需要特别注意,写的语句可能并不是自己想要的。

相关内容