这就是我到目前为止使用 jquery 所拥有的。我不知道为什么我的 checkRecord 按钮不会显示两个日期之间的天数。我显然错过了一些东西。
$(document).ready(function () {
'use strict';
var monthNames = [ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ];
var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
var newDate = new Date();
newDate.setDate(newDate.getDate());
$('#safetyRecord').hide();
$('#today').html(dayNames[newDate.getDay()] + "," +' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getDate() + ","+ ' ' + newDate.getFullYear());
$('#checkRecord').click(function(){
var $daysSinceLastAccident = $('#daysSinceLastAccident');
var dateOfLastAccident = new Date($('#dateOfLastAccident').val());
var today = new Date();
$daysSinceLastAccident = Math.floor((today.getTime() - dateOfLastAccident.getTime()) / (24 * 60 * 60 * 1000));
$daysSinceLastAccident.text(daysSinceLastAccident);
$('#safetyRecord').show();
});
});