我的想法不对,想得过于简单了,但又没有思路,只好请教各位大神。下面是代码:<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>倒计时</title>
<script type="text/javascript">
function check(i){
if (i<10) {
i='0'+i;
} return i;
}
function gettime(){
var myDate=new Date();
var year=myDate.getFullYear();
var month=myDate.getMonth()+1;
var date=myDate.getDate();
var hour=myDate.getHours();
var min=myDate.getMinutes();
var sec=myDate.getSeconds();
min=check(min);
sec=check(sec);
document.getElementById('show').innerHTML=year+'年'+month+'月'+date+'日'+hour+':'+min+':'+sec;
document.getElementById('show').style.display='block';
setTimeout(gettime,1000);
}
function hide(){
document.getElementById('show').style.display='none';
}
</script>
</head>
<body>
<div id="show" style="width:200px;border:1px solid red;display: none;"></div>
<input type="button" name="显示" value="显示时间" onclick="gettime()">
<input type="button" name="取消" value="取消显示" onclick="hide()">
</body>
</html>
添加回答
举报
0/150
提交
取消