亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

有點Bug。。點了stop后停止,再點2次start后再點stop就停止不了了....

<!DOCTYPE HTML>

<html>

<head>

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

<title>計時器</title>

<script type="text/javascript">

i=setInterval("clock()",1000);

? ?function clock(){

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

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

? ?}

? ? ?

function mystart(){

i=setInterval("clock()",1000);

}

? ? function myclear(){

? ? ? ? clearInterval(i);

? ? }

</script>

</head>

<body>

? <form>

? ? <input type="text" id="clock" size="50" ?/>

? ? <input type="button" value="Stop" onclick="myclear()" />

<input type="button" value="Start" onclick="mystart()" />


? </form>

</body>

</html>


正在回答

2 回答

是的,謝謝樓上的回答~^O^ ? 給我了一個思路。你這個代碼運行后如果先點一次start后還是停止不了...

下邊是在你基礎上改進的:

<!DOCTYPE HTML>

<html>

<head>

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

<title>計時器</title>

<script type="text/javascript">

var i=setInterval("clock()",1000);

var count = 0;

? ?function clock(){

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

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

? ? ? console.log(time);

? ?}

? ?function mystart(){

? ? if(count > 0 ){

? ? ? ?i=setInterval("clock()",1000);?

? count--;

? ? }

}

? ? function myclear(){

? ? ? ? clearInterval(i);

? ? ? ? count = 1;

? ? }

</script>

</head>

<body>

? <form>

? ? <input type="text" id="clock" size="50" ?/>

? ? <input type="button" value="Stop" onclick="myclear()" />

<input type="button" value="Start" onclick="mystart()" />

?

? </form>

</body>

</html>


2 回復 有任何疑惑可以回復我~

這個問題是,你點擊了多次開始。想到開啟了多個定時器。而你在關的時候只關了一個。所以會導致關不了。

<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
<title>計時器</title>
<script?type="text/javascript">
i=setInterval("clock()",1000);
???function?clock(){
??????var?time=new?Date();????????????????
??????document.getElementById("clock").value?=?time;
??????console.log(time);
???}
?????
?????var?count?=?0;
function?mystart(){
????if(count?==?0){
???????i=setInterval("clock()",1000);?
????}
????count?=?1;
}
????function?myclear(){
????????clearInterval(i);
????????count?=?0;
????}
</script>
</head>
<body>
??<form>
????<input?type="text"?id="clock"?size="50"??/>
????<input?type="button"?value="Stop"?onclick="myclear()"?/>
<input?type="button"?value="Start"?onclick="mystart()"?/>

??</form>
</body>
</html>

這樣是一個不優雅的解決辦法

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

有點Bug。。點了stop后停止,再點2次start后再點stop就停止不了了....

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號