本文介绍了如何跳出jQuery每个循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何跳出 jQuery each
循环?
How do I break out of a jQuery each
loop?
我试过了:
return false;
在循环中,但这不起作用.有什么想法吗?
in the loop but this did not work. Any ideas?
我把 return false;
放在了错误的地方.当我将它放入循环中时,一切正常.
I put the return false;
in the wrong place. When I put it inside the loop everything worked.
推荐答案
To break
a $.each
或 $(selector).每个
循环,你必须在循环回调中返回false
.
返回 true
跳到下一次迭代,相当于正常循环中的 continue
.
Returning true
skips to the next iteration, equivalent to a continue
in a normal loop.
$.each(array, function(key, value) {
if(value === "foo") {
return false; // breaks
}
});
// or
$(selector).each(function() {
if (condition) {
return false;
}
});
这篇关于如何跳出jQuery每个循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!