亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js實(shí)現(xiàn)秒表計(jì)時(shí)器

 更新時(shí)間:2019年12月16日 09:14:56   作者:yiran0101001  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)秒表計(jì)時(shí)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)秒表計(jì)時(shí)器的具體代碼,供大家參考,具體內(nèi)容如下

秒表計(jì)時(shí)器的實(shí)現(xiàn):

效果圖如下:

附代碼,已調(diào)試運(yùn)行

<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <title>Document</title>
 <style>
  #div1 {
   width: 300px;
   height: 400px;
   background: skyblue;
   margin: 100px auto;
   text-align: center;
  }
  
  #count {
   width: 200px;
   height: 150px;
   line-height: 150px;
   margin: auto;
   font-size: 40px;
  }
  
  #div1 input {
   width: 150px;
   height: 40px;
   background: orange;
   font-size: 25px;
   margin-top: 20px
  }
 </style>
</head>

<body>
 <div id="div1">
  <div id="count">
   <span id="id_H">00</span>
   <span id="id_M">00</span>
   <span id="id_S">00</span>
  </div>
  <input id="start" type="button" value="開(kāi)始">
  <input id="pause" type="button" value="暫停">
  <input id="stop" type="button" value="停止">
 </div>
 <script>
  //可以將查找標(biāo)簽節(jié)點(diǎn)的操作進(jìn)行簡(jiǎn)化 var btn = getElementById('btn')
  function $(id) {
   return document.getElementById(id)
  }
  window.onload = function() {
   //點(diǎn)擊開(kāi)始建 開(kāi)始計(jì)數(shù)
   var count = 0
   var timer = null //timer變量記錄定時(shí)器setInterval的返回值
   $("start").onclick = function() {
    timer = setInterval(function() {
     count++;
     console.log(count)
      // 需要改變頁(yè)面上時(shí)分秒的值
     console.log($("id_S"))
     $("id_S").innerHTML = showNum(count % 60)
     $("id_M").innerHTML = showNum(parseInt(count / 60) % 60)
     $("id_H").innerHTML = showNum(parseInt(count / 60 / 60))
    }, 1000)
   }
   $("pause").onclick = function() {
     //取消定時(shí)器
     clearInterval(timer)
    }
    //停止記數(shù) 數(shù)據(jù)清零 頁(yè)面展示數(shù)據(jù)清零
   $("stop").onclick = function() {
    //取消定時(shí)器
    $("pause").onclick()
     // clearInterval(timer)
     //數(shù)據(jù)清零 總秒數(shù)清零
    count = 0
     //頁(yè)面展示數(shù)據(jù)清零
    $("id_S").innerHTML = "00"
    $("id_M").innerHTML = "00"
    $("id_H").innerHTML = "00"
   }

   //封裝一個(gè)處理單位數(shù)字的函數(shù)
   function showNum(num) {
    if (num < 10) {
     return '0' + num
    }
    return num
   }
  }
 </script>
</body>

</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論