如何突破jQuery的每个循环如何突破jQuery?each循环?我试过: return false;在循环中,但这不起作用。有什么想法吗?
3 回答
一只名叫tom的猫
TA贡献1906条经验 获得超3个赞
break a $.each$(selector).eachfalse
truecontinue
$.each(array, function(key, value) {
if(value === "foo") {
return false; // breaks
}});// or$(selector).each(function() {
if (condition) {
return false;
}});
慕盖茨4494581
TA贡献1850条经验 获得超11个赞
我们可以中断$.each()循环[.]通过使回调函数返回false。
function callback(indexInArray, valueOfElement) {
var booleanKeepGoing;
this; // == valueOfElement (casted to Object)
return booleanKeepGoing; // optional, unless false
// and want to stop looping}continue
返回非false与for循环中的连续语句相同;它将立即跳到下一次迭代。
慕侠2389804
TA贡献1719条经验 获得超6个赞
$('.groupName').each(function() {
if($(this).text() == groupname){
alert('This group already exists');
breakOut = true;
return false;
}});if(breakOut) {
breakOut = false;
return false;}- 3 回答
- 0 关注
- 413 浏览
添加回答
举报
0/150
提交
取消
