?????? ??? ???
JavaScript Timing Events
JavaScript? ???? ??? ??? ??? ??? ??? ?? ?? ?? ??? ??? ? ????. ??? ??? ??? ????? ????.
JavaScript?? ??? ???? ???? ?? ????. ? ?? ?? ???? ??? ????.
setInterval() - ??? ??? ?? ?? ??? ??? ????? ?????.
setTimeout() - ??? ??? ?? ?? ??? ? ??? ??? ?????.
??: setInterval() ? setTimeout()? HTML DOM Window ??? ? ?? ??????.
setInterval() ???
setInterval()? ??? ??? ?? ??? ??? ????? ?????.
Syntax
window.setInterval("javascript function",milliseconds);
window.setInterval() ???? ??? ? ????. ?? ? ???? ???? setInterval() ??? ?? ?????.
setInterval() ? ?? ????? ?????.
? ?? ???? ??? ??? ?
??: 1000???? 1????.
3??? "hello" ??? ???.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <button onclick="myFunction()">點(diǎn)我</button> <script> function myFunction(){ setInterval(function(){alert("Hello")},3000); } </script> </body> </html>
??? ???? ??? ??????
clearInterval() ???? setInterval() ??? ??? ?? ??? ???? ? ?????.
Syntax
window.clearInterval(intervalVariable)
window.clearInterval() ???? ? ???? ???? ?? ?????clearInterval() ??? ??? ? ????.
clearInterval() ???? ????? ??? ???? ??? ? ?? ??? ???? ???.
myVar=setInterval("javascript function",milliseconds);
?? ?? ClearInterval() ???? ???? ??? ??? ? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script> var t = self.setInterval("clock()",50) function clock() { var time=new Date() document.getElementById("clock_show").innerHTML=time } </script> </head> <body> <p id="clock_show"></p> <button onclick="window.clearInterval(t)">停止計(jì)時(shí)</button> </body> </html>
setTimeout() ???
Syntax
window.setTimeout("javascript function", milliseconds);
setTimeout() ???? ?? ?? ?????. ?? ????? ?? t?? ??? ?????. ? setTimeout()? ????? ? ?? ????? ???? ??? ? ????.
setTimeout()? ? ?? ????? JavaScript ?? ???? ??????. ? ?? "alert('5 second!')"? ?? ?? ??, AlertMsg()"? ?? ??? ?? ??? ?? ????.
? ?? ????? ? ?? ????? ??? ?? ?????? ? ???? ????? ?????.
?: 1000???? 1?? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <button onclick="myFunction()">點(diǎn)我</button> <script> function myFunction(){ setTimeout(function(){alert("Hello")},3000); } </script> </body> </html>
??? ???? ???
clearTimeout() ???? setTimeout() ???? ?? ??? ???? ? ?????. )
window.clearTimeout() ??? ? ???? ??? ? ????.
clearTimeout() ???? ????? ?? ?? ?? ???(setTimeout)?? ?? ??? ???? ???.
myVar=setTimeout("javascript function",milliseconds);
??? ?? ???? ?? ????clearTimeout() ???? ???? ?? ?? ??? ??? ? ????
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script> var s = 0; var n = 0; var t; function timeCount() { document.getElementById('second_show').value = s; n = n+1; s = n/10; t = setTimeout("timeCount()",100); } </script> </head> <body> <form> <input type="button" value="開始計(jì)時(shí)" onClick="timeCount()"> <input type="text" id="second_show"> <input type="button" value="結(jié)束計(jì)時(shí)" onClick="clearTimeout(t)"> </form> </body> </html>
.