Home >Web Front-end >JS Tutorial >Jquery each method jumps out of the loop and gets the return value (explanation with examples)_jquery

Jquery each method jumps out of the loop and gets the return value (explanation with examples)_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 17:09:351453browse
return false: will stop the loop (just like using 'break' in a normal loop).
return true: Jump to the next loop (just like using 'continue' in a normal loop).
Copy code The code is as follows:

function test(){
var success = false ;
$(..).each(function () {
if (..) {
success = true;
return false;
}
});
return success ;
}

jquery is an object chain, so $(..).each() still returns a collection of objects. each(function(){}): It is a callback function. In the callback function, the result cannot be returned outside the callback function each.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn