The exit and continue learning record of the loop in js and jquery, jsjquery

Source: Internet
Author: User

The exit and continue learning record of the loop in js and jquery, jsjquery

As a commodity, I learned to record 1 + 1 = 3! Error: 2

Learning records:

In js

For (var I = 1; I <5; I ++) {if (I = 3) {break; // when break is used, 2 prompts are displayed, 1, and 2; if you use continue, it will pop up three times, namely 1, 2, 4} alert (I );}

Loop, exit the loop, use break; exit the current loop to continue the next loop, use continue

To implement break in the each () method in jquery, use return false; continue, use return true


For Loop in Jquery + JS

1. As said above
2. With each, you can see that the each explanation will be passed to the element index and content of the callback function. The index starts from 0, so add 1
$ (Document). ready (function (){
$ ("Div [id ^ = 'tab ']"). each (function (I ){
$ (This). mouseover (function (){
Alert (I + 1 );
});
});

});

How can I jump out of the each loop in jquery?

The each function is a multi-execution function that executes all matching elements once. First, if you exit the current execution, use return. Second, if you want to stop running until it is not executed, I have not found a method. We recommend that you set a range limit on the previous selector to avoid this situation.
 

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.