如何打破/退出JQuery中的每个()函数?

我有一些代码:

$(xml).find("strengths").each(function() { //Code //How can i escape from this block based on a condition. }); 

我怎样才能从“每个”代码块基于条件转义?

更新:

如果我们有这样的事情呢?

 $(xml).find("strengths").each(function() { $(this).each(function() { //I want to break out from both each loops at the same time. }); }); 

是否有可能从“每个”内部的“每个”function中分离出来?

#19.03.2013

如果你想继续而不是爆发

 return true; 

根据文件,你可以简单地return false; 打破:

 $(xml).find("strengths").each(function() { if (iWantToBreak) return false; }); 

从匿名函数返回false:

 $(xml).find("strengths").each(function() { // Code // To escape from this block based on a condition: if (something) return false; }); 

从每个方法的文档:

在每个函数中返回'false'会完全停止遍历所有元素的循环(这就像使用正常循环的'break'一样)。 从循环中返回'true'跳到下一个迭代(这就像使用正常循环的'continue'一样)。

你可以使用return false;

 +----------------------------------------+ | JavaScript | PHP | +-------------------------+--------------+ | | | | return false; | break; | | | | | return true; or return; | continue; | +-------------------------+--------------+ 
 if (condition){ // where condition evaluates to true return false } 

看到3天前问类似的问题 。