日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JavaScript学习05 定时器

發布時間:2023/12/18 javascript 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JavaScript学习05 定时器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

JavaScript學習05 定時器

?

定時器1

  用以指定在一段特定的時間后執行某段程序。

  setTimeout()

  格式:[定時器對象名=] setTimeout(“<表達式>”,毫秒)

  功能:執行<表達式>一次。

  例子:

<!DOCTYPE html> <html><head><title>timer1.html</title><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="this is my page"><meta http-equiv="content-type" content="text/html; charset=UTF-8"><!--<link rel="stylesheet" type="text/css" href="./styles.css">--><script type="text/javascript">function count(){setTimeout("alert('執行成功!')",7000);}</script></head><body><input type="button" value="點擊我啊" onclick="count();"></body> </html>

?

?

定時器2

  以一定的時間為間隔,不斷地重復執行表達式。

  setInterval()

  格式:[定時器對象名=] setInterval(“<表達式>”,毫秒)

  功能:重復執行<表達式>,直至窗口、框架被關閉或執行clearInterval。

  clearInterval()

  格式:clearInterval(定時器對象名)  

  功能:終止定時器

  例子:

<!DOCTYPE html> <html><head><title>timer2.html</title><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="this is my page"><meta http-equiv="content-type" content="text/html; charset=UTF-8"><!--<link rel="stylesheet" type="text/css" href="./styles.css">--><script type="text/javascript">var sec = 0;var timer = setInterval("count();",1000);//頁面加載的時候即開始計時function count(){document.getElementById("num").innerHTML = sec++;}function stopCount(){clearInterval(timer);//停止定時器的運行 }</script></head><body><font color="red" id="num">0</font><input type="button" value="停止" onclick="stopCount();"></body> </html>

?

參考資料

  圣思園張龍老師Java Web視頻教程。

  W3School JavaScript教程:http://www.w3school.com.cn/js/index.asp

  英文版:http://www.w3schools.com/js/default.asp

?

  JS Timing:http://www.w3school.com.cn/js/js_timing.asp

?

轉載于:https://www.cnblogs.com/mengdd/p/3680863.html

總結

以上是生活随笔為你收集整理的JavaScript学习05 定时器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。