如何在JQuery中打破/退出each()函数? [英] How to break/exit from a each() function in JQuery?

查看:247
本文介绍了如何在JQuery中打破/退出each()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码:

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

如何根据条件从每个代码块中逃脱?

How can i escape from the "each" code block based on a condition?

如果我们有这样的结果怎么办:

What if we have something like this:

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

是否可以从内部每个功能中突破每个功能?

Is it possible to break out from both "each" functions from the inner "each" function?

#19.03.2013

如果你想继续而不是突破

return true;


推荐答案

根据文档你可以简单地返回false; 来打破:

According to the documentation you can simply return false; to break:

$(xml).find("strengths").each(function() {

    if (iWantToBreak)
        return false;
});

这篇关于如何在JQuery中打破/退出each()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆