2012-11-22 42 views
3

如果選擇的日期是明天,我想要發出警報。這是我有:如果是明天,jQuery datepicker會觸發警報

$('#dateInput').datepicker({ 
    onSelect: function(dateText, inst) { 
     if (Date.parse(today)+1 == Date.parse(selectedDate)) { 
      alert('tomorrow!'); 
     } 
    } 
}); 

我怎樣才能使它發揮作用?

+0

你想在剛明天或所有月份的天火警報和明天一樣嗎? –

回答

1

這將在剛剛明天被解僱,而不是明天的所有月份同一天:

$('#dateInput').datepicker({ 
    onSelect: function(dateText, inst) { 
     var date_now = new Date(); 
     var date_today = date_now.getDate(); 
     var date_thismonth = date_now.getMonth(); 
     var date_thisyear = date_now.getFullYear(); 
     if (date_thisyear == inst.selectedYear && 
      date_thismonth == inst.selectedMonth && 
      (date_today+1) == inst.selectedDay){ 
      alert('tomorrow!'); 
     } 
    } 
});? 

http://jsfiddle.net/ue9Lh/

+0

輕微更正... –

0
$('#dateInput').datepicker({ 
    onSelect: function(dateText, inst) { 
     var todayDate = new Date(); 
     var tomorrowDate = new Date(todayDate.getTime() + (24 * 60 * 60 * 1000)).setHours(0,0,0,0); 
     var inputDate = new Date(dateText); 
     if (tomorrowDate - inputDate == 0) { 
     alert('tomorrow!'); 
     } 
    } 
}); 
0
$('#dateInput').datepicker({ 
    onSelect: function(dateText, inst) { 
     var tomorrow = new Date(); 
     tomorrow.setHours(0,0,0,0); 
     tomorrow.setDate(tomorrow.getDate()+1); 
     if (tomorrow.getTime() == Date.parse(dateText)) { 
      alert('tomorrow!'); 
     } 
    } 
}); 
+1

關於降價的內容是什麼? –