批改状态:合格
老师批语:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<title>Document</title>
<style>
*{padding:0%;margin: 0%;font-size: 1.2rem;color: white;}
div{width: 600px;height: 50px;background-color:lightcoral;position: absolute;left: 0%;top: 0%;bottom: 0%;right: 0;margin: auto;border-radius: 30px;}
#time{margin: 0 auto;display: block;line-height: 50px;text-align: center;}
div{box-shadow: 1px 2px 3px #888888;}
</style>
<script>
$(document).ready(function () {
//设置定时器,每1秒执行一次代码内容
setInterval(function () {
var myDate = new Date();//创建一个Date对象,存储当前时间
var toDate = new Date();//创建一个Date对象,存储目标时间
toDate.setFullYear(2019, 1, 5);//设置目标时间的年月日
toDate.setHours(0, 0, 0, 0);//设置目标时间的时分秒
var time = toDate - myDate;//目标时间-当前时间得出时间距离毫秒数
var days = parseInt(time / (1000 * 60 * 60 * 24));//将时间距离毫秒数转为天数
var hours = parseInt((time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));//将时间距离毫秒数转为小时数
var minutes = parseInt((time % (1000 * 60 * 60)) / (1000 * 60));//将时间距离毫秒数转为分钟数
var seconds = parseInt((time % (1000 * 60)) / 1000);//将时间距离毫秒数转为秒数数
$("#time").html("2019年农历春节倒计时" + days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds +
" 秒 ");
}, 1000);
});
</script>
</head>
<body>
<div>
<span id="time"></span>
</div>
</body>
</html>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号