<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
var i=setInterval(clock,1000);
function clock() {
var mytime =new Date();
var year =mytime.getFullYear();
var month =mytime.getMonth();
var date =mytime.getDate();
var week =mytime.getDay();
var weeks =["日","一","二","三","四","五","六"];
var day =weeks[week];
var hour =mytime.getHours();
var minute =mytime.getMinutes();
var second =mytime.getSeconds();
time_now =year+"年"+(month+1)+"月"+date+"日"+"星期"+day+hour+":"+minute+":"+second;
document.getElementById('txt').value=time_now;
}
function start() {
i=setInterval(clock,1000); /*我的问题:为什么如果这行写成“var i=setInterval(clock,1000)",第二次单击stop时stop按钮就失效了呢?为嘛非得去掉这个"var"?*/
}
</script>
</head>
<body>
<input type="text" id="txt" style="width:200px">
<input type="button" onclick="start()" value="start">
<input type="button" onclick="clearInterval(i)" value="stop">
</body>
</html>
Cassie_yu
至善笃行
nicole820
hulukid
相关分类