定时器简单理解

xiaoxiao2021-02-28  113

在开发工程中,网站的banner中,定时器的用处尤为突出 setTimeout(函数名,延迟);setTimeout("函数名()",间隔) 延迟循环定时器,setInterval(); function a(a,b){console.log(a+b) }; setInterval("a(8,3)",1000);//1000ms = 1s 。清除定时器,clearInterval(timer) var index = 0; var timer = setInterval(function(){ index++; if(index==5){ clearInterval(timer);//清除定时器 } console.log(index);//1 2 3 4 5 },1000); 模拟一个弹出一次判断是否是VIP会员: var person = "svip"; var x = setTimeout(function(){ if(person=="vip"){ clearTimeout(x); }else{ alert("请成为会员哦.."); } },2000); var date = new Date();   //获取现在时间       getFullYear();                  //获取全年 getMonth();                    //获取月份 getDate();                       //获取日期 getDay();                        //获取星期 getHours();                    //获取小时 getMinutes();                //获取分钟 getSeconds();                //获取秒数 getTime();                     //获取1970年1月1号到现在的毫米数 var date = new Date(); //alert(date);//当前时间 格林尼治时间 var year = date.getFullYear();//获取年份 var month = date.getMonth()+1;//0-11 --> 1-12(真实) var day = date.getDate();//获取日 var week = date.getDay();//获取星期几 0-->6 //获取时分秒 var hours = date.getHours();
转载请注明原文地址: https://www.6miu.com/read-31947.html

最新回复(0)