Each of the jquery uses return TRUE or false instead of break or continue_jquery

Source: Internet
Author: User
Copy Code code as follows:

function MethodOne () {
....
$.each (Array,function () {
if (condition set) {
return true;
}
});
....
}

In a function, there is a each, and in each case a condition is set, the function returns TRUE or FALSE

However, you cannot use break and continue within each block of code, and to implement the functions of break and continue, use other methods
Break----with return false;
Continue--use return ture;

So when I want to return to this function in each, I just let each continue and
Even each has no interruption, so the function cannot return.

Workaround: Try to catch throw out of the error, to exit each, and return the wrong target!
Copy Code code as follows:

function Checkbatchrow (obj) {
if ($ (": checkbox[id$= ' chkselect ']:checked '). Size () > 0) {
try {
$ (": checkbox[id$= ' Chkselect ']:checked"). each (function () {
var prefix = this.id.replace ("Chkselect", "");

var Txtdatestart = $ ("#" + prefix + "Txtdatestart");
var txtdateend = $ ("#" + prefix + "txtdateend");
if ($.trim (Txtdatestart.val ()) = = ' | | $.trim (txtdateend.val ()) = = ') {
Txtdatestart.addclass ("Farevalidform");
Txtdateend.addclass ("Farevalidform");
Throw "Sorry, please fill in the validity period!" ";

}
else {
D1arr = Txtdatestart.val (). Split ('-');
D2arr = Txtdateend.val (). Split ('-');
V1 = new Date (d1arr[0], d1arr[1], d1arr[2]);
v2 = new Date (d2arr[0], d2arr[1], d2arr[2]);
if (V2 < v1) {
Txtdateend.addclass ("Farevalidform");
Throw "Sorry, the end date cannot be less than the start date!" ";
}
}

var Txtremaindamt = $ ("#" + prefix + "Txtremaindamt");
if (Txtremaindamt.val (). Match (/^[0-9]+$/) = null) {
Txtremaindamt.addclass ("Farevalidform");
Throw "Sorry, the number of tickets must be a number!" ";
}
else {
if (Txtremaindamt.val () < 1) {
Txtremaindamt.addclass ("Farevalidform");
Throw "Sorry, the number of tickets must be greater than 0!" ";
}
}

var Txtfareprice = $ ("#" + prefix + "Txtfareprice");
if (Txtfareprice.val (). Match (/^[0-9]+0$/) = null) {
Txtfareprice.addclass ("Farevalidform");
Throw "Sorry, the par price must be a number, and a multiple of 10!" ";
}
});

catch (e) {
Popupmsg (e);
return false;
}

return customconfirm (obj, ' Are you sure you want to update? ');
}
else {
Popupmsg ("Sorry, you did not modify any items!") ");
return false;
}
}

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.