如果选择的日期是明天,我想要发出警报。这就是我所拥有的:
$('#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!');
}
}
});?
答案 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!');
}
}
});