This time I will bring you an in-depth introduction to JavaScript timers. What are the precautions for using JavaScript timers? The following is a practical case, let’s take a look.
Get the year, month, day, week, hour, minute and secondsetTimeout Delay type: How much delay ms execution
setTimeout delay type, only executed once
var btn1 = document.getElementById('btn1');var btn2 = document.getElementById('btn2');var i = 0;var timer = null; btn1.onclick = function () { //开启定时器 timer = setInterval(function () { i++; alert(i); },1000); }
btn2.onclick = function () { i = 0; clearInterval(timer); }
str[0];不兼容低版本浏览器,如IE7等; var a = 'abcdef';alert(a[0]); str.charAt(0); 兼容各种浏览器 var a = 'abcdef';a.charAt(0); //兼容各种浏览器
数字时钟 ![](image/0.png) ![](image/0.png) : ![](image/0.png) ![](image/0.png) : ![](image/0.png) ![](image/0.png)
In-depth basic application of JavaScript
The above is the detailed content of In-depth JavaScript timer. For more information, please follow other related articles on the PHP Chinese website!