在查詢按鈕點擊事件中加入日期比對邏輯,防止無效範圍提交。
function calendarSearch() {
var sd = $('#startDate').datebox('getValue');
var ed = $('#endDate').datebox('getValue');
if (!sd || !ed) {
alert('請選擇日期!');
return false;
}
if (sd >= ed) {
alert('開始日期不能大於或等於結束日期!');
return false;
}
// 執行查詢邏輯
return true;
}
datebox('getValue') 取得格式化字串(yyyy-MM-dd),字串比較即可判斷大小。return false 阻止表單提交或 AJAX 發送。