each函数不能使用break和continue关键字,替代方法是:
根据如下:
Fortunately there is another way for breaking and continuing a jQuery loop. You can [color=blue]break[/color] a jQuery loop by [color=blue]returning false[/color] in the function argument. A [color=olive]continue[/color] can be implemented by just doing a [color=olive]return without[/color] specifying a return value or by returning any other value than false.
[url=http://www.factsandpeople.com/facts-mainmenu-5/26-html-and-javascript/101-continue-and-break-in-a-jquery-loop]factsandpeople[/url]
$('.container').each(function(i){
if($(this).attr('name')=="continue"){
return ;//实现continue功能
}else if($(this).attr('name')=="break"){
return false;//实现break功能
}
})
根据如下:
Fortunately there is another way for breaking and continuing a jQuery loop. You can [color=blue]break[/color] a jQuery loop by [color=blue]returning false[/color] in the function argument. A [color=olive]continue[/color] can be implemented by just doing a [color=olive]return without[/color] specifying a return value or by returning any other value than false.
[url=http://www.factsandpeople.com/facts-mainmenu-5/26-html-and-javascript/101-continue-and-break-in-a-jquery-loop]factsandpeople[/url]
本文介绍在jQuery的each函数中如何模拟使用break和continue关键字的方法。通过返回特定值来达到跳出当前循环或跳过本次循环的目的。
597

被折叠的 条评论
为什么被折叠?



