码迷,mamicode.com
首页 > 编程语言 > 详细

javascript平时小例子④(setInterval使用2)

时间:2016-11-10 12:10:09      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:order   rip   dao   element   put   utf-8   cond   body   java   

<!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 = (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)

标签:order   rip   dao   element   put   utf-8   cond   body   java   

原文地址:http://www.cnblogs.com/cxy66/p/6050269.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!