第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

計(jì)時(shí)器程序無法停止計(jì)時(shí)

寫了好多遍,都是能開始就停不了,能停就不能開始,我希望能實(shí)現(xiàn)點(diǎn)擊start按鈕,text框(初始為null)開始計(jì)時(shí),點(diǎn)擊stop,計(jì)時(shí)結(jié)束。

<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html?xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>無標(biāo)題文檔</title>
<script?type="text/javascript">
function?gg_1(){
var?s=new?Date();
document.getElementById("time").value=s;
}
var?i=setInterval(gg_1,100);
function?ss(){
clearInterval(i);
}
</script>
</head>

<body>
<input?type="button"?id="start"?value="Start"?onclick="gg_1()"/>
<input?type="text"?id="time"?/>
<input?type="button"?id="stop"?value="Stop"?onclick="ss()"/>
</body>
</html>



正在回答

5 回答

您想要的是計(jì)時(shí),而你寫的是時(shí)間的,有點(diǎn)矛盾,計(jì)時(shí)器用setTimeout()比較好,看下我的代碼:(注意看下注釋部分

<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html?xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>無標(biāo)題文檔</title>
<script?type="text/javascript">
??var?i;
??var?num=0;
??function?st(){
	??document.getElementById("time").value=num;
	??num=num+1;
	???i=setTimeout(st,1000);
}

??function?ss(){
	??clearTimeout(i);
	}
	
??//var?i;//這里是第二種寫法
??//var?num=0;
??//var?n=true;
??//function?gg_1(){
??//	document.getElementById("time").value=num;
??//	num=num+1;
??//	?i=setTimeout(gg_1,1000);
??//}
??//function?st(){
??//	if(n==true){
??//		clearTimeout(i);//這里如果把clearTimeout(i);num=0;注釋掉,就和上面的類似;不注釋掉,再次點(diǎn)擊start時(shí),會(huì)重新開始計(jì)時(shí)
??//		num=0;??????????//但是,上面的方法會(huì)有個(gè)bug,就是,連續(xù)多次點(diǎn)擊start按鈕,計(jì)時(shí)會(huì)加速
??//		setTimeout(gg_1,1000);
??//		n=false;
??//		}
??//	}
??//
??//function?ss(){
??//	if(n==false){
??//	clearTimeout(i);
??//	n=true;
??//	}
??//	}
?</script>
</head>
?
<body>
<input?type="button"?id="start"?value="Start"?onclick="st()"/>
<input?type="text"?id="time"?/>
<input?type="button"?id="stop"?value="Stop"?onclick="ss()"/>
</body>
</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

連枝 提問者

非常感謝!
2016-10-27 回復(fù) 有任何疑惑可以回復(fù)我~
#2

錦衣無涯

function st()函數(shù)是你定義的開始函數(shù)對(duì)吧,為什么函數(shù)里第二句有clearTimeout(i)這個(gè)取消定時(shí)器的指定?百思不得其解,已經(jīng)要開始了為什么要定義先取消再執(zhí)行。
2017-02-05 回復(fù) 有任何疑惑可以回復(fù)我~
#3

錦衣無涯 回復(fù) 錦衣無涯

并沒有重新計(jì)時(shí) 多此一舉
2017-02-05 回復(fù) 有任何疑惑可以回復(fù)我~

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>計(jì)時(shí)器</title>

<script type="text/javascript">

? var num=0;

? var i;

? function startCount(){

? ? document.getElementById('count').value=num;

? ? num=num+1;

? ? i=setTimeout("startCount()",1000);

? }

? flag=0;

? function stopCount(){

? ? ? if(flag==0){

? ? ? ? ? flag=1;

? ? ? ? ? document.getElementById('but').value="Stop";

? ? ? startCount();

? ? ? }else{

? ? ? ? ? clearTimeout(i);

? ? ? ? ? flag=0;

? ? ? ? ? document.getElementById('but').value="Start";

? ? ? }

? }

? function ce(){

? ? ? if(flag==0){

? ? ? document.getElementById('count').value="清除完畢!";

? ? ? num=0;

? ? ? setTimeout("document.getElementById('count').value=num",1000);

? ? ? }

? }

</script>

</head>

<body>

? <form>

? ? <input type="text" id="count" />

? ? <input type="button" id="but" value="Start" onclick="stopCount()" />

? ? <input type="button" value="Clear" ?onclick="ce()" />

? </form>

</body>

</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

qq_灰色頭像_17

這個(gè)可以一直用,start和stop自動(dòng)切換,從大神那里cope的
2017-09-04 回復(fù) 有任何疑惑可以回復(fù)我~

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>無標(biāo)題文檔</title>

<script type="text/javascript">

? ? window.onload=function(){

? ? ? timer = setInterval("abc()",1000)

? ? }

? ??

? ? function abc(){

? ? ? ? var s=new Date();

? ? ? ? document.getElementById("time").value=s;

? ? }

? ? ?

? ? function bcd(){

? ? ? clearInterval(timer);

? ? }


? ? function efg(){

? ? ? timer = setInterval("abc()",1)

? ? }

</script>

</head>

<body>

<input type="button" id="start" value="Start" onclick="efg()"/>

<input type="text" id="time" />

<input type="button" id="stop" value="Stop" onclick="bcd()"/>

</body>

</html>

重寫了一下 這個(gè)好像可以了

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

連枝 提問者

謝謝你,我把你的代碼全部拷進(jìn)DW里運(yùn)行了一下,start和stop全部失效,還是不行
2016-10-19 回復(fù) 有任何疑惑可以回復(fù)我~
#2

Shero_25 回復(fù) 連枝 提問者

在我這是可以正常運(yùn)行啦 但是先點(diǎn)開始會(huì)有問題 點(diǎn)擊停止 再點(diǎn)開始 這樣反復(fù)操作是沒問題的
2016-10-19 回復(fù) 有任何疑惑可以回復(fù)我~

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>無標(biāo)題文檔</title>

<script type="text/javascript">


function gg_1(){

? ? var s=new Date();

? ? document.getElementById("time").value=s;

}


function aaa(){

? ? setInterval(gg_1,100);

}


var i=setInterval(gg_1,100);

function ss(){ ? ?

? ? clearInterval(i);

}

</script>

</head>

?

<body>

<input type="button" id="start" value="Start" onclick="aaa()"/>

<input type="text" id="time" />

<input type="button" id="stop" value="Stop" onclick="ss()"/>

</body>

</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

Shero_25

還是不對(duì) 這樣只有第一次好使 ??
2016-10-19 回復(fù) 有任何疑惑可以回復(fù)我~

woyebuhui

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

計(jì)時(shí)器程序無法停止計(jì)時(shí)

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)