我真的需要帮助计算两个日期之间的差异,它必须是整数中的天数。这是我的 HTML 和 jQuery ..
这根本不起作用......该网站应该说今天的日期。然后用户将选择日期并单击“检查我们的安全记录”按钮,并在页面底部显示已经过了多少天。jQuery:
$(document).ready(function() {
$('#safetyRecord').hide();
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());
$('#today').html(dayNames[newDate.getDay()] + "," +' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getDate() + ","+ ' ' + newDate.getFullYear());
/*
$(':button').click(function(){
var start = $('#dateOfLastAccident').val();
var end = $('#today');
var startDate = new Date(start);
var endDate = new Date(end);
var diff = endDate - StartDate;
var numDays = Math.floor( diff / 1000 /60 /60 /24 );
$('#daysSinceLastAccident'+ numDays)();
*/
});
的HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>generic safety</title>
<link rel="stylesheet" href="L3hw.css">
<!-- jQuery library hosted by Google Content Distribution Network -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="L3hw.js"></script>
</head>
<body>
<header>
<img src="images/genericBanner.png" alt="Generic, Inc.">
<p>
The New Ventures Mission is to scout profitable growth opportunities in
relationships, both internally and externally, in emerging, mission-inclusive
markets, and explore new paradigms and then filter and communicate and
evangelize the findings.
</p>
</header>
<section id="main">
<h1>Safety at generic company</h1>
<h2>Today is <span id="today">TBD</span>.<br>
Our last lost-work accident was on
<input type="date" id="dateOfLastAccident">
<button type="button" id="checkRecord">Check our safety record</button>
</h2>
<h2 id="safetyRecord">
It has been <span id="daysSinceLastAccident">TBD</span> days since our last lost-work accident.
</h2>
</section> <!-- end main -->
<footer>
<p id="message">
<!-- (an appropriate safety message will appear here) -->
</p>
<p><img src="images/genericBullet.png" alt="*"> Generic Company - we do stuff</p>
</footer>
</body>
</html>