data对象 定时器

<!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>
    input{
        text-align: right;
        font-weight:bold;

    }
    </style>
</head>
<body>
    minutes:<input type="text" value="0" >
    seconds:<input type="text" value="0">
    <script type="text/javascript">
     var minutesCode=document.getElementsByTagName('input')[0];
     var secondsCode=document.getElementsByTagName('input')[1];
     var seconds=0,
         minutes=0;
     var timer= setInterval(function (){
         seconds++;
         if(seconds==60){
           minutes++;
           seconds=0;
         }
         secondsCode.value=seconds;
         minutesCode.value=minutes;
         if(minutes==3){
         clearInterval(timer);
     }
     },10)
   
    //  setInterval(function (){
    //  console.log('s');
    //  },200)   //////定时器
    // var firstTime=new Date().getTime();
    // setInterval(function (){
    // var lastTime=new Date().getTime();
    // console.log(lastTime-firstTime);  
    // firstTime=lastTime;
    // },1000);
    </script>
</body>
</html>
//setInterval()
setTiemout()推迟一段时间在执行
clearInterval()
clearTimeout()

 

posted @ 2020-03-08 13:48  尚宇园  阅读(165)  评论(0编辑  收藏  举报