jquery hints syntaxerror:unlabeled break must is inside loop or switch

Source: Internet
Author: User

JavaScript jumps out of the loop in general with a break.

Colleagues encountered this problem, subconsciously used the break, want to jump out of this cycle. Result error
Syntaxerror:unlabeled break must be inside loop or switch

After investigation, should use a

Return False in the callback function, which is true of most JQ methods.

The code is as follows:
returning ' false ' will stop the loop (like using ' break ' in an ordinary loop).
Returns ' true ' to the next loop (like using ' Continue ' in an ordinary loop).

jquery jumps out of each loop instance

The code is as follows Copy Code

var arr = ["abc", "EF", "gggg"];
$.each (arr, function (index, value)
{
If (This = = "abc")
return false;
}
);

jquery returns false; just jump out of the loop ~ do you want to return the value or do it outside the loop?

The code is as follows

The code is as follows Copy Code
function Test () {
var success = false;
$(..). each (function () {
If (..) {
Success = true;
return false;
}
});
return success;
}

Related tutorials: Simple analysis of jquery each () Method usage and optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.