課程
/前端開發(fā)
/JavaScript
/JavaScript進(jìn)階篇
停止和計(jì)時(shí)開始該怎么相互轉(zhuǎn)換呢?
2014-11-21
源自:JavaScript進(jìn)階篇 8-4
正在回答
//參考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計(jì)時(shí)器</title>
<script type="text/javascript">
? var attime;
? function check(a){
? ? ? if(a<10){
? ? ? ? ? a = "0" + a;
? ? ? }
? ? ? return a;
? ? }
? function clock(){
? ? var time=new Date(); ? ? ? ? ?
? ? attime=time.getHours() + ":" + check(time.getMinutes()) + ":" + check(time.getSeconds());
? ? document.getElementById("clock").value = attime;
}
? var stop = setInterval("clock()",1000);
</script>
</head>
<body>
? <form>
? ? <input type="text" id="clock" size="50" ?/>
? ? <input type="button" value="Stop" onclick="clearInterval(stop)" /> ? //停止
? ? <input type="button" value="begin" onclick="stop=setInterval('clock()',1000)" /> ?//恢復(fù)
? </form>
</body>
</html>
你可以寫兩個(gè)函數(shù),一個(gè)是清除計(jì)時(shí)器,另一個(gè)是開啟計(jì)時(shí)器,分別在兩個(gè)按鈕的事件中調(diào)用就可以了
舉報(bào)
本課程從如何插入JS代碼開始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
8 回答怎么讓一個(gè)計(jì)時(shí)器可以不停地暫停和開始呢
3 回答點(diǎn)擊開始和停止沒用?
2 回答為什么點(diǎn)了 停止之后 點(diǎn)開始 再點(diǎn)停止 這個(gè)時(shí)間就是停不下來(lái)呢?
1 回答執(zhí)行多次開始得相應(yīng)的執(zhí)行多少次停止才能停止
3 回答我這段js計(jì)時(shí)器的開始和停止按鈕的代碼哪有錯(cuò)誤?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2014-12-10
//參考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計(jì)時(shí)器</title>
<script type="text/javascript">
? var attime;
? function check(a){
? ? ? if(a<10){
? ? ? ? ? a = "0" + a;
? ? ? }
? ? ? return a;
? ? }
? function clock(){
? ? var time=new Date(); ? ? ? ? ?
? ? attime=time.getHours() + ":" + check(time.getMinutes()) + ":" + check(time.getSeconds());
? ? document.getElementById("clock").value = attime;
}
? var stop = setInterval("clock()",1000);
</script>
</head>
<body>
? <form>
? ? <input type="text" id="clock" size="50" ?/>
? ? <input type="button" value="Stop" onclick="clearInterval(stop)" /> ? //停止
? ? <input type="button" value="begin" onclick="stop=setInterval('clock()',1000)" /> ?//恢復(fù)
? </form>
</body>
</html>
2014-11-21
你可以寫兩個(gè)函數(shù),一個(gè)是清除計(jì)時(shí)器,另一個(gè)是開啟計(jì)時(shí)器,分別在兩個(gè)按鈕的事件中調(diào)用就可以了