Teb*_*ebo 602 javascript jquery
我有一些代码:
$(xml).find("strengths").each(function() {
//Code
//How can i escape from this block based on a condition.
});
Run Code Online (Sandbox Code Playgroud)
如何根据条件从"每个"代码块中逃脱?
如果我们有这样的事情怎么办:
$(xml).find("strengths").each(function() {
$(this).each(function() {
//I want to break out from both each loops at the same time.
});
});
Run Code Online (Sandbox Code Playgroud)
是否有可能从内部"每个"功能中突破"每个"功能?
#19.03.2013
如果你想继续而不是爆发
return true;
Run Code Online (Sandbox Code Playgroud)
Gre*_*reg 1002
根据文档,你可以简单return false;
地打破:
$(xml).find("strengths").each(function() {
if (iWantToBreak)
return false;
});
Run Code Online (Sandbox Code Playgroud)
Sub*_*axe 116
您可以使用 return false;
+----------------------------------------+
| JavaScript | PHP |
+-------------------------+--------------+
| | |
| return false; | break; |
| | |
| return true; or return; | continue; |
+-------------------------+--------------+
Run Code Online (Sandbox Code Playgroud)
Guf*_*ffa 106
从匿名函数返回false:
$(xml).find("strengths").each(function() {
// Code
// To escape from this block based on a condition:
if (something) return false;
});
Run Code Online (Sandbox Code Playgroud)
从每种方法的文档:
从每个函数中返回'false'会完全停止循环遍历所有元素(这就像使用带有正常循环的'break').从循环内返回'true'会跳到下一次迭代(这就像使用带有正常循环的'continue').
ada*_*ign 24
if (condition){ // where condition evaluates to true
return false
}
Run Code Online (Sandbox Code Playgroud)
3天前看到类似的问题.