jquery每次早退

标签 jquery each

我在数组上有一个 jQuery for-each 循环,想知道是否可以提前离开循环。

$(lines).each(function(i){  
    // some code  
    if(condition){  
        // I need something like break;  
    }  
});

break; 实际上不起作用,这是有原因的。

如果我写一个 for 循环,它看起来像这样(但我不想要那样):

for(i=0; i < lines.length; i++){  
    // some code  
    if(condition){  
        break; // leave the loop 
    }  
};

提前致谢 -马丁

最佳答案

根据docs :

If you wish to break the each() loop at a particular iteration you can do so by making your function return false. Returning non-false is the same as a continue statement in a for loop, it will skip immediately to the next iteration.

关于jquery每次早退,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1857186/

上一篇:jQuery 文本匹配

下一篇:jquery同步函数

相关文章:

javascript - Ajax 数据库更新后重新呈现 fullCalendar 中的事件

javascript - jQuery $.each() 会摸索非数组对象是否具有 length 属性

javascript - Ajax 推进

javascript - 无法在 Trent Richardson 日期时间选择器中显示图标

jquery - 如何将 add rel ="lightbox"附加到特定链接?

jquery - 获取输入字段的标签

ruby-on-rails-3 - Rails 3-如何处理从数据库获取的数据

javascript - 需要在 .each 元素之间添加时间延迟

Jquery - 将 .each() 与变量和 IF 语句一起使用

JavaScript 循环内触发事件