JavaScript定时器方法
2024-09-01 23:57:29
一、setTimeout() 延迟性操作
window.setTimeout(function(){
console.log('派大星');//延迟了4秒
},4000);
console.log('海绵宝宝'); //定时器 异步运行
function hello(){
alert("hello");
} var t1 = window.setTimeout(hello,1000);//使用方法名字执行方法
var t2 = window.setTimeout("hello()",3000);//使用字符串执行方法
二、setInterval() 定时输出
var num = 0;
var timer = null;
timer = setInterval(function(){
num++;
if(num>5){
clearInterval(timer);
return;
}
console.log('num:'+num);
},1000);//1秒输出一次 //实时刷新 时间单位为毫秒
setInterval('refreshQuery()',8000);
/* 刷新查询 */
function refreshQuery(){
console.log('每8秒调一次')
}
最新文章
- Oracle统计函数之Lead
- IT软件开发常用英语词汇
- 10 Ways to Inspire Your Team
- 顺序表(C++)
- Swift结构体与类
- Git Github jekyll,gem Liquid模板语言 Markdown
- TCP 滑动窗口
- JavaScript关于js垃圾回收
- 安装VC6.0安装步骤及心得体会
- mysql登录报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
- linux驱动工程面试必问知识点
- dubbo配置方式简单介绍
- c++中虚析构函数
- learning at command AT+CSQ
- js android页面被挂起问题解决
- PHP的extension_dir设置问题
- 字符串化#、拼接字符##和可变参数宏(...和_ _VA_ARGS_ _)
- day0201
- 本地测试ajax遇到的跨域问题
- c# 如何制作RealPlayer 视频播放器