Js setInterval与setTimeout(定时执行与循环执行)的代码(可以传入参数)
时间:2024-04-16 09:23:29
Document自带的方法:
循环执行:var timeid = window.setInterval(“方法名或方法”,“延时”);window.clearInterval(timeid);
定时执行:var tmid = window.setTimeout(“方法名或方法”, “延时”);window.clearTimeout(tmid);
举例说明:
A.当要执行的方法中不需要参数时
<script type=”text/javascript”>
//循环执行,每隔3秒钟执行一次showalert()
window.setInterval(showalert, 3000);
function showalert()
{
alert(“aaaaa”);
}
//定时执行,5秒后执行show()
window.setTimeout(show,5000);
function show()
{
alert(“bbb”);
}
</script>
B.当要执行的方法中需要参数时
<script type=”text/javascript”>
//循环执行,每隔3秒钟执行一次 showalert()
window.setInterval(function(){
showalert(“aaaaa”);
}, 3000);
function showalert(mess)
{
alert(mess);
}
//定时执 行,5秒后执行showalert()
window.setTimeout(function(){
showalert(“bbbbbb”);
},5000);
</script>
标签:定时执行,循环执行
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Python自动化Microsoft Excel和Word的操作方法
2023-04-11 16:15:21
![](https://img.aspxhome.com/file/2023/3/75953_0s.png)
mysql通过文档读取并执行命令之快速为mysql添加多用户和数据库技巧
2024-01-24 01:45:02
mysql: 安装后的目录结构
2011-03-08 09:46:00
golang微服务框架基础Gin基本路由使用详解
2023-07-23 10:31:19
python热力图实现简单方法
2023-10-28 06:14:41
oracle复制表结构和复制表数据语句分享
2023-07-07 02:43:43
python实现神经网络感知器算法
2021-03-06 11:23:39
![](https://img.aspxhome.com/file/2023/9/91979_0s.png)
完美解决python遍历删除字典里值为空的元素报错问题
2023-04-23 13:39:50
结束运行python的方法
2022-12-07 02:56:02
python爬取各省降水量及可视化详解
2023-08-04 15:19:57
![](https://img.aspxhome.com/file/2023/9/124769_0s.png)
Pandas中如何对DataFrame列名进行重命名
2021-06-14 23:46:38
Asp无组件上传进度条解决方案
2010-04-24 16:01:00
Python爬虫实现简单的爬取有道翻译功能示例
2022-05-30 14:08:37
tensorflow 1.X迁移至tensorflow2 的代码写法
2023-07-19 08:30:54
php while循环控制的简单实例
2024-05-11 10:03:54
Pandas数据离散化原理及实例解析
2022-06-26 21:45:14
![](https://img.aspxhome.com/file/2023/8/97748_0s.png)
如何提升JavaScript的运行速度(函数篇)
2010-05-17 13:27:00
Golang并发编程之调度器初始化详解
2023-07-13 08:47:11
![](https://img.aspxhome.com/file/2023/5/99635_0s.png)
Tensorflow 2.4 搭建单层和多层 Bi-LSTM 模型
2021-03-30 16:25:06
Pandas中Series的属性,方法,常用操作使用案例
2021-11-22 05:00:47
![](https://img.aspxhome.com/file/2023/1/83771_0s.png)