<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>练习</title>
<meta charset="UTF-8">
</head>
<body>
<input type="text" id="clock" style="width:280px">
<input type="button" value="begin" onclick="onclick_begin()">
<input type="button" value="end" onclick="end_cilck()">
<input type=‘button‘ value="setTimeout" onclick="f()">
<script>
function begin() {
var c_time=getdate();
var ret=document.getElementById(‘clock‘);
ret.value=c_time;
}
var ID;
function onclick_begin(){
if (ID==undefined){begin();
ID=setInterval(begin,1000);
}
}
function end_cilck() {
clearInterval(ID);
ID=undefined;
}
function getdate() {
var date_obj=new Date();
var year_=date_obj.getFullYear();
var month_=date_obj.getMonth()+1;
var date_=date_obj.getDate();
var hour_=date_obj.getHours();
var min_=date_obj.getMinutes();
var sec_=date_obj.getSeconds();
var week=date_obj.getDay();
return year_+‘年‘+month_+‘月‘+f(date_)+‘日‘+hour_+‘时‘+min_+‘分‘+sec_+‘秒‘+getweek(week);
function f(num){
if (num<10){
return ‘0‘+num;
}
return num;
}
function getweek(n){
weeks=[‘星期日‘,‘星期一‘,‘星期二‘,‘星期三‘,‘星期四‘,‘星期五‘,‘星期六‘];
return weeks[n];
}
}
//==================setTimeout,clearTimeout====================================
function ci() {
alert(123);
}
function f() {
var ID=setTimeout(ci,1000);
clearTimeout(ID)
}
</script>
</body>
</html>
window单击事件练习