如果明天是jQuery datepicker火警

时间:2012-11-22 13:02:22

标签: jquery date datepicker

如果选择的日期是明天,我想要发出警报。这就是我所拥有的:

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

我怎样才能让它发挥作用?

3 个答案:

答案 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/

答案 1 :(得分: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!');
        }
   }
});

答案 2 :(得分: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!');
        }
   }
});