有人可以告诉我我做错了什么吗?我是jquery新手,希望获得一些反馈。基本上我想要的是某种倒数计时器,可以显示事件发生前还剩下多少天。该事件是一个设定的日期。
感谢您的帮助
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Almost Vacation</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$('document').on('ready', calc);
function calc(){
var myDate = new Date();
myDate.setMonth(05, 06);
var today = new Date();
today.getDay();
var x = myDate - today;
$('#aantal p').text(x);
}
</script>
<style type="text/css">
p {
color:red;
font-size:1.8em;
margin:-90px 10px 5px;
}
</style>
</head>
<body>
<img src="http://fed.cmd.hro.nl/upload/files/1011/y1/q4/w3/slapende_student.jpg" width="462" height="275" />
<p>Vacation starts in<span id="aantal"> </span> Days</p>
</body>
</html>
最佳答案
它必须是:
$(function() {
var myDate = new Date();
myDate.setMonth(06, 06); //set date forward in time, not backward
var today = new Date();
var x = (myDate - today)/86400000;
$('#aantal').text(x); //append to the span, not the p that does not exists
});
Fiddle