setInterval()与clearInterval()的用法
setInterval() 方法可按照指定的周期来调用函数或计算表达式。 --简单地说就是过一段时间调用一次该函数
setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的参数。代码演示如下
var backId=setInterval("aaa()",1000);
$('.aaa').mouseover(function(){
clearInterval(backId);
}).mouseout(function(){
backId=setInterval("aaa()",1000);
});
function aaa(){
alert(1);
}
当页面打开时没过1秒执行一次aaa方法,当鼠标移动到$('.aaa')对象上,aaa方法被停止调用,当鼠标离开$('.aaa')对象,又每隔一秒调用一次aaa方法。
关键是若要关闭定时调用aaa方法必须要根据定时设置调用aaa()方法所返回的返回值再利用clearInterval()去关闭它,这个返回值很关键。
setInterval()与clearInterval()的用法的更多相关文章
- JavaScript--定时器setTimeout()、clearTimeout(var param)和setInterval()、clearInterval(var param)
1.setTimeout().clearTimeout(var param) setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式,只调用一次 clearTimeout() 方法可取 ...
- setInterval 与 clearInterval详解
首先注意,setInterval与clearInterval都是直属于window对象的. 1.直接调用setInterval(即不通过函数调用) <div id="oDiv_show ...
- JS不间断向上滚动 setInterval和clearInterval
<div id=demo style=overflow:hidden;height:139;width:232;background:#f4f4f4;color:#ffffff><d ...
- setInterval setTimeout clearInterval
setTimeout() 只执行 code 一次.如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeout(). //第一次load的时候就先刷新一次 ...
- (二)学习JavaScript之setInterval和clearInterval方法
参考:http://www.w3school.com.cn/jsref/met_win_setinterval.asp HTML DOM Window 对象 定义和用法 setInterval() 方 ...
- setInterval()、clearInterval()、setTimeout()和clearTimeout()js计数器方法
原文地址:http://caibaojian.com/setinterval-settimeout.html window.setInterval()方法 介绍 周期性地调用一个函数(function ...
- 用javascript编写的小游戏(getElementById , setInterval , clearInterval , window.onload , innerText 和页面跳转, 标签的使用)
(1)图片轮转 <script type="text/javascript" > ; setInterval(function(){ var dom=document. ...
- setInterval和clearInterval
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- js setInterval和clearInterval 的使用
setInterval(函数名, 时间); 函数名:不需要加括号: 时间:单位是毫秒: 例子: var inter= setInterval(searchTasksByCnd, 10 * 100 ...
随机推荐
- 【java】for循环输出数字金字塔
输出下列数字金字塔. 1 121 123211234321 public class deng { public static void main(String args[]) { int n ...
- 收藏的技术文章链接(ubuntu,python,android等)
我的收藏 他山之石,可以攻玉 转载请注明出处:https://ahangchen.gitbooks.io/windy-afternoon/content/ 开发过程中收藏在Chrome书签栏里的技术文 ...
- C# 常用函数和方法集
1.DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 1.1 取当前年月日时分秒 currentTime=System. ...
- JAVA I/O使用方法(转)
下面四张图表明了类之间的继承关系,其中红色.加粗的类名是常用的类. 常用转换 FileReader——>BufferedReader BufferedReader in= new Buffere ...
- mysql binlog 混合模式 出现的基于sql的数据不一致,主要是now()这类函数导致
- Leetcode:Swap Nodes in Pairs 单链表相邻两节点逆置
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- Python下载Bing主页图片
直接上代码: # -*- coding: cp936 -*- import urllib import os print 'Download data......' url = 'http://cn. ...
- cron 定时任务
cron 是linux下的定时任务: M H D m d cmd. 这是一种cron文件格式. M: 分钟(0-59). H:小时(0-23). D:天(1-31). m: 月(1-12). d ...
- sublime text 3解放鼠标的快捷键总结
Sublime text 3是我最喜欢的代码编辑器,每天和代码打交道,必先利其器,掌握基本的代码编辑器的快捷键,能让你打码更有效率.刚开始可能有些生疏,只要花一两个星期坚持使用并熟悉这些常用的快捷键, ...
- 有关android源码编译的几个问题
项目用到编译环境,与源码有些差异不能照搬,关键是连源码都没编译过,下面基本上是行网上照的各种自学成才的分享,病急乱投医了,都记在下面作为参照吧. 1.验证是否编译正确,在终端执行 emulator & ...