jquery的each函数中的break和continue功能

来源:互联网 发布:可以查询淘宝账号 编辑:程序博客网 时间:2024/05/14 15:13
each函数不能使用break和continue关键字,替代方法是: 
Java代码  收藏代码
  1. $('.container').each(function(i){  
  2.      if($(this).attr('name')=="continue"){  
  3.           return ;//实现continue功能  
  4.      }else if($(this).attr('name')=="break"){  
  5.           return false;//实现break功能  
  6.      }  
  7. })  

根据如下: 

Fortunately there is another way for breaking and continuing a jQuery loop. You can break a jQuery loop byreturning false in the function argument. A continue can be implemented by just doing a return withoutspecifying a return value or by returning any other value than false. 

0 0