課程
/前端開發(fā)
/JavaScript
/JavaScript進(jìn)階篇
為什么點(diǎn)一下按鈕,文本框的數(shù)字就只加一;;而我要效果是點(diǎn)一下按鈕,文本框內(nèi)容就從0開始自動(dòng)計(jì)數(shù),請(qǐng)問哪里寫錯(cuò)了??????
2015-03-07
源自:JavaScript進(jìn)階篇 8-5
正在回答
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>計(jì)時(shí)器</title>
</head>
<script>
window.onload=function ()
{
? ? var oTxt1=document.getElementById("txt1");
? ? var oBtn1=document.getElementById("btn1");
? ? var num=0;
? ??
? ? oBtn1.onclick=function tt()
? ? {
? ? ? ? ?var time=setTimeout(function(){
? ? ? ? ? num++;
oTxt1.value=num;
setTimeout(tt(),0);
},1000);
? ? }
}
</script>
<body>
<form>
<input id="txt1" type="text" />
<input id="btn1" type="button" value="點(diǎn)擊" />
</form>
</body>
</html>
Ewall_ 提問者
menghuanbaolei 回復(fù) Ewall_ 提問者
<!DOCTYPE?HTML> <html> <head> <meta?charset="utf-8"> <title>計(jì)時(shí)器</title> </head> <script> window.onload=function?() { ????var?oTxt1=document.getElementById("txt1"); ????var?oBtn1=document.getElementById("btn1"); ????var?num=0; ???? ????oBtn1.onclick=function?tt() ????{ ?????????var?time=setTimeout(function(){ ????????? num++; oTxt1.value=num; setTimeout(tt(),0); },1000); ????} ???? } </script> </head> <body> <form> <input?id="txt1"?type="text"?/> <input?id="btn1"?type="button"?value="點(diǎn)擊"?/> </form> </body> </html>
舉報(bào)
本課程從如何插入JS代碼開始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
1 回答關(guān)于定時(shí)器多次啟動(dòng)/關(guān)閉問題
2 回答關(guān)于計(jì)時(shí)器
1 回答關(guān)于計(jì)時(shí)器
1 回答關(guān)于取消計(jì)時(shí)器
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)
2015-03-07
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>計(jì)時(shí)器</title>
</head>
<script>
window.onload=function ()
{
? ? var oTxt1=document.getElementById("txt1");
? ? var oBtn1=document.getElementById("btn1");
? ? var num=0;
? ??
? ? oBtn1.onclick=function tt()
? ? {
? ? ? ? ?var time=setTimeout(function(){
? ? ? ? ? num++;
oTxt1.value=num;
setTimeout(tt(),0);
},1000);
? ? }
? ??
}
</script>
</head>
<body>
<form>
<input id="txt1" type="text" />
<input id="btn1" type="button" value="點(diǎn)擊" />
</form>
</body>
</html>
2015-03-07