上课留了个小玩意,结果读错了题。。。。。分享一下代码
`<style>
div{
height:50px;
line-height:50px;
text-align:center;
border:double #ccc;
width:100px;
}
</style>
<script type="text/javascript">
var t ;//注意下,这个t必须要是全局变量
var flag = true;
function contral(){
flag ? startDate():clearTimeout(t);
flag = !flag;
}
function startDate(){
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
//在这里要对分和秒做判断
m = checkDate(m);
s = checkDate(s);
document.getElementById('clock').innerHTML = h+':'+m+':'+s;
t = setTimeout('startDate()',1000);
return t;
}
function checkDate(i){
if(i<10) return '0'+i;
return i;
}
</script>
<div id="clock"></div>
<button onclick="contral()">开始/暂停</button>
<script>
</script>
`