首页 > 代码库 > javascript平时小例子④(setInterval使用2)
javascript平时小例子④(setInterval使用2)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
* {
margin: 0 auto;
}
#kaishi {
text-align: center;
background-color: red;
width: 300px;
height: 100px;
border: 1px solid black;
}
</style>
</head>
<body>
<div id="kaishi">
距离2017年还有
<br />
<input type="text" id="daojishi" / style="text-align: center;">
<script>
window.onload=function(){
setInterval(function() {
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth() + 1;
var day = time.getDate();
var hours = time.getHours();
var minutes = time.getMinutes();
var secomds = time.getSeconds();
tian = 0;
if(month == 8 || month == 10 || month == 12) {
tian = 31;
} else if(month == 9 || month == 11) {
tian = 30;
}
document.getElementById("daojishi").value = http://www.mamicode.com/(2017 - year - 1) +"年" + (12 - month - 1) + "月" + (tian - day - 1) + "日" + (24 - hours - 1) + "时" + (60 - minutes - 1) + "分" + (60 - secomds - 1) + "秒";
}, 1000);
}
</script>
</div>
</body>
</html>
javascript平时小例子④(setInterval使用2)