課程
/前端開(kāi)發(fā)
/JavaScript
/JavaScript進(jìn)階篇
我這里不懂出現(xiàn)了什么問(wèn)題,實(shí)現(xiàn)不了對(duì)應(yīng)功能功能
2015-11-29
源自:JavaScript進(jìn)階篇 8-4
正在回答
if (i) { ? ?clearInterval(i); ? ?//取消定時(shí)后要把i清空,不然的話(huà)就進(jìn)不了后面的else ? ?i = null;}else { ? ?i = setTimeout(timedCount, 1000);}
timedCount 這是個(gè)什么東西?setTimeout這個(gè)定時(shí)只執(zhí)行一次就停止
以上的問(wèn)題和你本問(wèn)題無(wú)關(guān),因?yàn)槟愀静粫?huì)執(zhí)行到上面的代碼。
<input type="button" value="Stop" onclick="clearInterval(i)"/> ? 你這樣就只是調(diào)了取消,不會(huì)再啟動(dòng)了
吾愛(ài)吾師 提問(wèn)者
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計(jì)時(shí)器</title>
<script type="text/javascript">
? ?function clock(){
? ? ? var time=new Date(); ? ? ? ? ? ? ? ?
? ? ? document.getElementById("clock").value = time;
? ?}
? ? ?var i=setInterval(clock,1000);
? ? ?function runOrstop(){
? ? ? ? ?if(i)
? ? ? ? ?{
? ? ? ? ? ? clearInterval(i);
? ? ? ? ?}
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? i=setInterval(clock,1000);
? ? ? ? }
? ? ?}
</script>
</head>
<body>
? <form>
? ? <input type="text" id="clock" size="50" ?/>
? ? <input type="button" value="Stop" onclick="runOrstop()" ?/>
? </form>
</body>
</html>
這樣對(duì)了沒(méi)有?可是我還是實(shí)現(xiàn)不了功能
舉報(bào)
本課程從如何插入JS代碼開(kāi)始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
1 回答不選的功能實(shí)現(xiàn)不了 哪里出錯(cuò)了
4 回答為什么只有+功能實(shí)現(xiàn)不了?
1 回答為什么我實(shí)現(xiàn)不了切換功能呢?
2 回答功能不能實(shí)現(xiàn)
2 回答怎么選項(xiàng)卡功能實(shí)現(xiàn)不了?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-11-29
if (i) {
? ?clearInterval(i);
? ?//取消定時(shí)后要把i清空,不然的話(huà)就進(jìn)不了后面的else
? ?i = null;
}else {
? ?i = setTimeout(timedCount, 1000);
}
timedCount 這是個(gè)什么東西?setTimeout這個(gè)定時(shí)只執(zhí)行一次就停止
以上的問(wèn)題和你本問(wèn)題無(wú)關(guān),因?yàn)槟愀静粫?huì)執(zhí)行到上面的代碼。
<input type="button" value="Stop" onclick="clearInterval(i)"/> ? 你這樣就只是調(diào)了取消,不會(huì)再啟動(dòng)了
2015-11-30
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計(jì)時(shí)器</title>
<script type="text/javascript">
? ?function clock(){
? ? ? var time=new Date(); ? ? ? ? ? ? ? ?
? ? ? document.getElementById("clock").value = time;
? ?}
? ? ?var i=setInterval(clock,1000);
? ? ?function runOrstop(){
? ? ? ? ?if(i)
? ? ? ? ?{
? ? ? ? ? ? clearInterval(i);
? ? ? ? ?}
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? i=setInterval(clock,1000);
? ? ? ? }
? ? ?}
</script>
</head>
<body>
? <form>
? ? <input type="text" id="clock" size="50" ?/>
? ? <input type="button" value="Stop" onclick="runOrstop()" ?/>
? </form>
</body>
</html>
這樣對(duì)了沒(méi)有?可是我還是實(shí)現(xiàn)不了功能