これは私がこれまでjqueryを使用してきたものです。私の checkRecord ボタンが 2 つの日付の間の日数を表示しない理由がわかりません。私は明らかに何かが欠けています。
$(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();
});
});