Jquery each loop break usage

Source: Internet
Author: User

Jquery each loop break usage
To implement the break and continue functions, use other methods.
Break ---- return false;
Continue -- use return ture;

Function methodone (){
....
$. Each (array, function (){
If (condition true ){
Return true;
}
});
....
}


When you want to use return true in each to return the function, you only need to let the each continue to execute
The each is not interrupted, so the function cannot return.

Let's take a look at a jquery each instance.

In jquery's each method, a break is added to the callback function according to the condition to jump out of the loop. Finally, I checked the usage document. In the past, if the callback function returns false, we can call up the loop. If we want to continue, we can return non-false.

Var len = 0;
Selectedrows. each (function (index ){
If ($ jquery (this). parents ("tr"). find ("span: last"). text () = "process "){
Alert ("records being processed cannot be deleted ");
Return false; // equivalent to break;
}
Len ++;
});


Instance 2

$. Fn. check = function (mode ){
Var mode = mode | 'on'; // if mode is undefined, use 'on' as default
Return this. each (function (){
Switch (mode ){
Case 'on ':
This. checked = true;
Break;
Case 'off ':
This. checked = false;
Break;
Case 'toggle ':
This. checked =! This. checked;
Break;
}
});
};

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.