最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

定時器1

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

  setTimeout():

  格式:[定時器對象名=] 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>

定時器2

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

  setInterval():

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

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

  clearInterval():

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

  功能:終止定時器

  例子:

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

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

相關(guān)文章

最新評論

梅河口市| 安阳市| 健康| 阿克| 枝江市| 来安县| 瑞丽市| 天祝| 泾阳县| 鲁山县| 伊金霍洛旗| 兴山县| 铁岭县| 册亨县| 嘉兴市| 钟山县| 盱眙县| 稻城县| 潞城市| 新泰市| 夹江县| 汉沽区| 土默特右旗| 惠水县| 陇南市| 浦东新区| 洛南县| 四平市| 乌拉特中旗| 清远市| 沿河| 顺平县| 阳春市| 微博| 长阳| 南陵县| 莲花县| 崇文区| 荆门市| 莆田市| 昌都县|