jquery $.each()循环退出

$.each()循环跳出,应该用return 来返回

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

continue --用return true; 

如果想要使用return终止方法的话,要用try catch 方式,代码如下

 

    1. try{    
    2.   $.each(Array,function(key,val) {     
    3.     if( aaa){     
    4.             throw('');   
    5.     }  
    6.   })  
    7.   }catch(e){                                
    8.     return; //在这里return  
    9.    }  

posted on 2018-07-05 20:10  范景锋  阅读(360)  评论(0编辑  收藏  举报

导航