我正在尝试计算 2 个日期选择器字段之间的天数,并在输入字段中显示该值。
如何获取两个日期日期选择器和手动选择之间的天数?
本工作手册仅选择:
$(function() {
$("#arrdatepicker").datepicker({
showOn: "button",
buttonImage: "calendar-ico.gif",
buttonImageOnly: true,
onSelect: function(dateText, inst) {
//dateText comes in as MM/DD/YY
var datePieces = dateText.split('/');
var month = datePieces[0];
var day = datePieces[1];
var year = datePieces[2];
//define select option values for
//corresponding element
$('select#arrmonth').val(month);
$('select#arrday').val(day);
$('select#arryear').val(year);
}
});
$("#depdatepicker").datepicker({
showOn: "button",
buttonImage: "calendar-ico.gif",
buttonImageOnly: true,
onSelect: function(dateText, inst) {
//dateText comes in as MM/DD/YY
var datePieces = dateText.split('/');
var month = datePieces[0];
var day = datePieces[1];
var year = datePieces[2];
//define select option values for
//corresponding element
$('select#depmonth').val(month);
$('select#depday').val(day);
$('select#depyear').val(year);
}
});
});
function dateDifference() {
var ev,honap,nap;
var datDate1 = new Date();
var datDate2 = new Date();
var napok;
ev = document.booking.arrivalyear.value;
honap = document.booking.arrivalmonth.value-1;
nap = document.booking.arrivalday.value;
datDate1.setFullYear(ev,honap,nap);
ev = document.booking.departureyear.value;
honap = document.booking.departuremonth.value-1;
nap = document.booking.departureday.value;
datDate2.setFullYear(ev,honap,nap);
napok = Math.floor((datDate2-datDate1)/(24*60*60*1000));
document.getElementById('label').innerHTML=napok+" nights";
}