2011-04-12 117 views
0

我想在當前日期之前的任何日期點擊日曆時顯示彈出消息嗎?這是具有用戶點擊日期的功能。 setCalendarControlDate(年,月,日)具有用戶選擇的日期。我如何比較日期並顯示錯誤。不應選擇當前日期之前的日期

function setCalendarControlDate(year, month, day) { 

calendarControl.setDate(year, month, day); 
var arguments = "changeDataGrid;day=" + day; 
arguments += ";month=" + month; 
arguments += ";year=" + year; 
// arguments += ";rowId=" + rowId; 
arguments += ";" + rowId; 
arguments += ";"; 

document.getElementById(targetControlId.id).value = arguments; 
document.forms[0].submit(); 

}

回答

2
var selectedDate = new Date(year, month-1, day); 

var valid = selectedDate >= new Date(); 


// If today was 12th April 2011 
year = 2011; 
month = 4; 
day = 13; 

var selectedDate = new Date(year, month-1, day); 

var valid = selectedDate >= new Date(); 

valid ; //# => true 

year = 2011; 
month = 4; 
day = 11; 

selectedDate = new Date(year, month-1, day); 

var valid = selectedDate >= new Date(); 

valid ; //# => false 
相關問題