Jquery cannot use break or continue to jump out of the each loop solution

Source: Internet
Author: User
Tags numeric value

The each function cannot use the break and continue keywords. The alternative method is:

Break ---- return false;

Continue -- use return ture; conditions

Analysis

Execute a function using each matching element as the context.
This means that each time the passed function is executed, the this keyword in the function points to a different DOM element (each time it is a different matching element ). In addition, each time a function is executed, a numeric value indicating the position of the element used as the execution environment in the matched element set is passed to the function as the parameter (an integer starting from scratch ). If 'false' is returned, the loop is stopped (just like using 'break' in a normal loop '). Return 'true' to jump to the next loop (just like using 'contine' in a normal loop ').


Code

The code is as follows: Copy code

$ ('. INER'). each (function (I ){

If ($ (this). attr ('name') = "continue "){

Return; // implement the continue function

} Else if ($ (this). attr ('name') = "break "){

Return false; // implement the break function

}

})

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.