欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript學(xué)習(xí)筆記之定時(shí)器

 更新時(shí)間:2015年01月22日 10:51:08   投稿:hebedich  
本文通過(guò)2個(gè)定時(shí)器的示例向我們展示了javascript中定時(shí)器的使用方法,格式以及功能,希望通過(guò)本文能夠讓大家對(duì)javascript定時(shí)器有新的認(rèn)識(shí)。

定時(shí)器1

  用以指定在一段特定的時(shí)間后執(zhí)行某段程序。

  setTimeout():

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

  功能:執(zhí)行<表達(dá)式>一次。

  例子:

復(fù)制代碼 代碼如下:

<!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('執(zhí)行成功!')",7000);
     }
    </script>
  </head>
  <body>
    <input type="button" value="點(diǎn)擊我啊" onclick="count();">
  </body>
</html>

定時(shí)器2

  以一定的時(shí)間為間隔,不斷地重復(fù)執(zhí)行表達(dá)式。

  setInterval():

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

  功能:重復(fù)執(zhí)行<表達(dá)式>,直至窗口、框架被關(guān)閉或執(zhí)行clearInterval。

  clearInterval():

  格式:clearInterval(定時(shí)器對(duì)象名)  

  功能:終止定時(shí)器

  例子:

復(fù)制代碼 代碼如下:

<!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);//頁(yè)面加載的時(shí)候即開始計(jì)時(shí)
     function count()
     {
        document.getElementById("num").innerHTML = sec++;
     }
     function stopCount()
     {
         clearInterval(timer);//停止定時(shí)器的運(yùn)行
     }
    </script>
  </head>
  <body>
    <font color="red" id="num">0</font>
    <input type="button" value="停止" onclick="stopCount();">
  </body>
</html>

以上就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡

相關(guān)文章

最新評(píng)論