我使用以下代码检查日期是否在今天之前!但是当我今天选择时,条件变为真实!
var fromDate = $('#from').datepicker('getDate');
var toDate = $('#to').datepicker('getDate');
var today = new Date();
if(today >= fromDate || toDate <= today){
alert('Cannot book dates prior to today.');
$('#from, #to').val('')
return false;
}
我在这里做错了什么?
答案 0 :(得分:4)
应该像
var fromDate = $('#from').datepicker('getDate');
var toDate = $('#to').datepicker('getDate');
var today = new Date();
today.setHours(0,0,0,0);
fromDate.setHours(0,0,0,0);
toDate.setHours(0,0,0,0);
if(today > fromDate || toDate < today){
alert('Cannot book dates prior to today.');
$('#from, #to').val('')
return false;
}