js 多setInterval冲突的解决方法
来源:互联网 发布:不亦说乎的说的读音 编辑:程序博客网 时间:2024/06/05 03:23
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>测试</title> </head> <script>var firstInterval;var secondInterval;function start(){firstAlert();secondAlert();}function firstAlert(){if(firstInterval) {clearInterval(firstInterval);}fun1();firstInterval = setInterval('firstAlert()', 10000);}function secondAlert(){if(secondInterval) {clearInterval(secondInterval);}fun2();secondInterval = setInterval('secondAlert()', 1000);} function fun1(){ console.log(getNowFormatDate() + '------ fun1'); }function fun2(){ console.log(getNowFormatDate() + '------ fun2'); }function getNowFormatDate() {var date = new Date();var seperator1 = "-";var seperator2 = ":";var month = date.getMonth() + 1;var strDate = date.getDate();if (month >= 1 && month <= 9) {month = "0" + month;}if (strDate >= 0 && strDate <= 9) {strDate = "0" + strDate;}var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate+ " " + date.getHours() + seperator2 + date.getMinutes()+ seperator2 + date.getSeconds();return currentdate;}</script> <body> <input type="button" onclick="start()" value="开始"/></body> </html>
0 0
- js 多setInterval冲突的解决方法
- 多个setInterval 冲突问题
- jQuery和JS文件冲突的解决方法
- JS的setInterval嵌套问题
- js定时器setInterval()的使用
- js中 setInterval的妙用
- js的setInterval函数语法
- JS setInterval setTimeout的用法
- jquery和其它js库起冲突的解决方法
- jquery和其他js库起冲突的解决方法
- jquery与js函数冲突的两种解决方法
- JS与DOCTYPE冲突导致漂浮代码失效的解决方法
- jquery类库和其他js类冲突的解决方法
- js鼠标单击和双击事件冲突问题的解决方法
- js鼠标单击和双击事件冲突问题的解决方法
- js鼠标单击和双击事件冲突问题的解决方法
- jquery类库和其他js类冲突的解决方法
- JS setInterval()、 setInterval()与 clearInterval() 方法的使用
- Android背景图片平铺
- Android多线程----异步消息处理机制之Handler
- Apache Shiro简介
- 归档— NSKeyedArchiver
- Genymotion 问题解决之 镜像下载(二)
- js 多setInterval冲突的解决方法
- 用canvas画一个钟表
- 屏幕适配
- Javascript中apply、call、bind的区别
- 一念執著
- 作品展收获
- Web前端基本用法(一)
- hadoop 兼容问题
- C#线程篇---Windows调度线程准则