標籤: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實現計數器,定時警告和停止