驗證失敗時,我需要幫助才能退出JavaScript代碼。目前,當驗證失敗但JavaScript代碼繼續運行時,我收到了正確的錯誤消息。請在下面找到我的代碼。由於驗證失敗時退出javascript代碼
var CompPlanID=1;
var Component=2;
var TierNo=3;
var StartDate=4;
var EndDate=5;
var TierMin=6;
var TierMax=7;
var Rate=8;
var InvalidFlag = 0;
var BlankTextBox = '';
function DateCheck()
{
var StartDateform= document.getElementById('tblTarget').rows[1].cells[StartDate].getElementsByTagName('input')[0].value;
var EndDateform= document.getElementById('tblTarget').rows[1].cells[EndDate].getElementsByTagName('input')[0].value;
var eDate = new Date(EndDateform);
var sDate = new Date(StartDateform);
if(StartDateform== BlankTextBox || EndDateform == BlankTextBox || sDate> eDate)
{
alert("Please ensure that the End Date is greater than or equal to the Start Date.");
InvalidFlag = 1;
}
}
//檢查PK行不爲空
//調用如果驗證爲真時提交功能。
if(InvalidFlag == 0)
{
$('button_submit').click();
alert('The new rate submitted');
}
}
使用'返回false;' –
使用返回false; –
除了'return false;'檢查函數的返回值('if(!CheckPkRow())return false;') – Zeta