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

jQuery.each函数不能使用break和continue关键字,替代方法是:

$('.container').each(function(i){
     if($(this).attr('name')=="continue"){
          return ;//实现continue功能
     }else if($(this).attr('name')=="break"){
          return false;//实现break功能
     }
})

 

依据资料:

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 without specifying a return value or by returning any other value than false.

posted @ 2013-07-11 13:44  魏朝辉  阅读(183)  评论(0)    收藏  举报