但是在each代碼塊內(nèi)不能使用break和continue,要實(shí)現(xiàn)break和continue的功能的話,要使用其它的方式
break----用return false;
continue --用return ture;
所以當(dāng)我在each里想使用return true給這個function返回時,其實(shí)只是讓each繼續(xù)執(zhí)行而以
連each都沒有中斷,所以function也就不能return了 。
解決辦法:通過try捕捉throw出來的錯誤,達(dá)到退出each、并返回錯誤的目標(biāo)!
代碼如下:
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 "對不起,請您填寫有效期!";
}
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 "對不起,結(jié)束日期不能小于開始日期!";
}
}
var txtRemaindAmt = $("#" + prefix + "txtRemaindAmt");
if (txtRemaindAmt.val().match(/^[0-9]+$/) == null) {
txtRemaindAmt.addClass("fareValidForm");
throw "對不起,機(jī)票數(shù)量必須為數(shù)字!";
}
else {
if (txtRemaindAmt.val() < 1) {
txtRemaindAmt.addClass("fareValidForm");
throw "對不起,機(jī)票數(shù)量必須大于0!";
}
}
var txtFarePrice = $("#" + prefix + "txtFarePrice");
if (txtFarePrice.val().match(/^[0-9]+0$/) == null) {
txtFarePrice.addClass("fareValidForm");
throw "對不起,票面價必須為數(shù)字,且為10的倍數(shù)!";
}
});
} catch (e) {
PopupMsg(e);
return false;
}
return CustomConfirm(obj, '您確定要更新嗎?');
}
else {
PopupMsg("對不起,您沒有修改任何項(xiàng)!");
return false;
}
}
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com