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;
}
}