Javascript實現計數器,定時警告和停止

來源:互聯網
上載者:User

標籤:java

1 <html> 2 <head> 3 <meta charset="utf-8"> 4 <title>定時警告</title> 5 </head> 6 <body>  7     <!--定時警告的問題--> 8     <h1>定時警告的問題</h1> 9     <input type="button" value="定時警告" onclick="setTimeMsg()"/>10     <script language="javascript">11         function setTimeMsg(){12             setTimeout(‘alert("hello world!!!")‘,3000);//3s13         }14     </script>15     <hr>16     <!--計數器-->17     <h1>計數器</h1>18     <input type="button" value="開始計時" onclick="startTime()"/>19     <input type="text" id="num"/><br>20     <input type="button" value="結束計時" onclick="stopTime()"/>21     22     <script language="javascript">23         var i=0;24         var t;25         function startTime(){26             document.getElementById("num").value=i;27             i=i+1;28             t=setTimeout("startTime()",10);//1s29         }30         31         function stopTime(){32             clearTimeout(t);33         }34     </script>35     36 </body>37 </html>

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;margin:0px;padding:0px;" />

650) this.width=650;" src="http://images2015.cnblogs.com/blog/1002211/201609/1002211-20160925102925584-1666888652.png" style="border:0px;height:auto;margin:0px;padding:0px;" />

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;margin:0px;padding:0px;" />

 1 <html> 2 <head> 3 <meta charset="utf-8"> 4 <title>定時警告</title> 5 </head> 6 <body onload="startTime()">  7     <h1>秒錶<div id="time"></div></h1> 8     <script language="javascript"> 9         function startTime(){10             var date=new Date();11             var year=date.getFullYear();12             var month=date.getMonth()+1;13             var day=date.getDate();14             var hour=date.getHours();15             var minute=date.getMinutes();16             var second=date.getSeconds();17             //var str=year+"年"+month+"月"+day+"日"+hour+":"+minute+":"+second;18             var str=hour+":"+minute+":"+second;19 20             document.getElementById("time").innerHTML=str;21             setTimeout("startTime()",1000);22         }23     </script>24 </body>25 </html>

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;margin:0px;padding:0px;" />

650) this.width=650;" src="http://images2015.cnblogs.com/blog/1002211/201609/1002211-20160925103022885-254250948.png" style="border:0px;margin:0px;padding:0px;" />

 


Javascript實現計數器,定時警告和停止

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.