To implement break and continue functions, use a different approach
Break----with return false;
Continue--use return ture;
The code is as follows |
Copy Code |
function MethodOne () { .... $.each (Array,function () { if (condition set) { return true; } }); .... } |
Each time you want to return to this function with returns True, just let each continue to execute and
There's no interruption to each, so the function can't return.
Let's look at a jquery each instance
jquery each method, in the callback function in accordance with the conditions added a break, jump out of the loop, who knows useless. Finally checked the use of the document, the original to return false in the callback function can be called loop, if you want to continue, return not false on the line.
The code is as follows |
Copy Code |
var len = 0; Selectedrows.each (function (index) { if ($jquery (this). Parents ("tr"). Find ("Span:last"). Text () = "process") { Alert ("Cannot delete the record being processed"); Return false;//equivalent to break; } len++; }); |
Example Two
The code is as follows |
Copy Code |
$.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 } }); }; |