>  기사  >  웹 프론트엔드  >  각 Jquery에서 break 또는 continue_jquery 대신 return true 또는 false를 사용하세요.

각 Jquery에서 break 또는 continue_jquery 대신 return true 또는 false를 사용하세요.

WBOY
WBOY원래의
2016-05-16 16:47:331204검색
코드 복사 코드는 다음과 같습니다.

function methodone(){
....
$.each(array,function(){
if(조건이 true){
return true;
}
})
....
} break--return false
continue - return true를 사용하세요.

각각에서 return true를 사용합니다. 이 함수로 돌아올 때 실제로는 각각이 중단되더라도
없이 계속 실행되도록 허용하므로 함수가 반환될 수 없습니다.

해결책: 각각의 종료 및 오류 반환 목표를 달성하려면 발생 오류 캡처 시도를 사용하세요!




코드 복사
코드는 다음과 같습니다. function CheckBatchRow(obj) { if ($ (":checkbox[id$='chkSelect']:checked").size() > 0) { try {
$(":checkbox[id$='chkSelect']: selected") .each(function() {
var prefix = this.id.replace("chkSelect", "");

var txtDateStart = $("#" prefix "txtDateStart");
var txtDateEnd = $("#" 접두사 "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 "죄송합니다. 종료 날짜는 시작 날짜보다 이전일 수 없습니다!";
}
}

var txtRemaindAmt = $("#" 접두사 "txtRemaindAmt" )
if (txtRemaindAmt.val().match(/^[0-9] $/) == null) {
txtRemaindAmt.addClass("fareValidForm") ;
throw "죄송합니다. 티켓 수량은 숫자여야 합니다! ";
}
else {
if (txtRemaindAmt.val() < 1) {
txtRemaindAmt.addClass("fareValidForm");
throw "죄송합니다. 티켓 수는 0보다 커야 합니다! ";
}
}

var txtFarePrice = $("#" 접두사 "txtFarePrice");
if (txtFarePrice.val().match(/^[0-9] 0$/) == null) {
txtFarePrice.addClass("fareValidForm");
throw "죄송합니다. 액면가는 숫자와 10의 배수여야 합니다! ";
}
});

} catch (e) {
PopupMsg(e);
false 반환;
}

CustomConfirm 반환 (obj, '업데이트하시겠습니까?');
}
else {
PopupMsg("죄송합니다. 항목을 수정하지 않았습니다!")
return false; >}
}

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.