window.setInterval()
功能:按照指定的周期(以毫秒计)来调用函数或计算表达式。
语法:setInterval(code,millisec)
解释:code:在定时时间到时要执行的JavaScript代码串。
millisec:设定的定时时间,用毫秒数表示。
返回值:定时器的ID值,可用于clearInterval()方法停止指定的定时器。
注:setInterval()方法会不停地调用函数,直到用clearInterval()终止定时或窗口被关闭。
window.clearInterval()
功能:取消由setInterval()方法设置的定时器。
语法:clearInterval(id_of_setinterval)
解释:id_of_setinterval:由setInterval()返回的ID值。该值标识了一个setInterval定时器。
也就是:window.setInterval()返回的就是window.clearInterval的参数
例子:
<script type="text/javascript">
var count = 0;
var timeID;
function timeCount()
{
document.getElementByIdx('timetxt').value = count;
count++;
}
function beginCount()
{
timeID = setInterval("timeCount()",1000);
}
function stopCount()
{
clearInterval(timeID);
}
</script>
<input type="button" value="开始计时" onclick="beginCount()" />
<input type="text" id="timetxt" size="5" />
<input type="button" value="停止计时" onclick="stopCount()" />
再如:
var objTimer = window.setInterval("moveDiv()",10)是调动定时器,其中moveDiv是js的一个函数
if(objTimer) window.clearInterval(objTimer)是停止定时器
分享到:
相关推荐
window.clearInterval与window.setInterval的用法.
1)window.setInterval(函数名称,时间);//间隔定时器(反复调用),时间的单位是毫秒 2)window.clearInterval(定时器的返回值);停止定时器 3)window.setTimeout(函数名称,时间)//延时定时器,执行一次 4)...
由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的参数。 提示: 1000 毫秒= 1 秒。 语法 setInterval(code,millisec,lang) 参数 描述 code 必需。要调用的函数或要执行的代码串。 millisec 必须...
Document自带的方法: 循环执行:var timeid = window.setInterval(“方法名或方法”,“延时”);window.clearInterval(timeid); 定时执行:var tmid = window.setTimeout(“方法名或方法”, “延时”);window....
熟练window对象的open、close、alert、confirm、prompt、setTimeout、clearTimeout、setInterval、clearInterval、moveBy、resizeBy、scrollBy方法的使用 掌握window对象的moveTo、resizeTo、scrollTo、print方法...
如果检测到窗口已经关闭,则需要掉用clearInterval()终止监测行为。 1、创建一个新的窗口: var newWin = window.open(url,name,"height=500,width=1000"); $("body",parent.document).mask("信息编辑中..."); 2、...
js-window属性大全,window对象的open、close、alert、confirm、prompt、setTimeout、clearTimeout、setInterval、clearInterval、moveBy、resizeBy、scrollBy方法的使用,掌握window对象的moveTo、resizeTo、scrollTo...
Window Control Methods Section 13.9. The Location Object Section 13.10. The History Object Section 13.11. Multiple Windows and Frames Chapter 14. The Document Object Section 14.1. ...
js 定时器 执行一次和重复执行 1- 执行一次(延时定时器) var t1 = window.setTimeout(function() { console.log(‘1秒钟之后执行了’...window.clearInterval(t2) // 去除定时器 $(function () { setInterval(function
var time = window.setInterval("active()", 100); function active() { if(newWin.closed){ clearInterval(time); return; } else if(x < screen.availWidth){ x+=dx; } else { clearInterval(time); }...
该方法会不停地循环调用函数,直到使用 clearInterval() 明确停止该函数或窗口被关闭。clearInterval() 函数的参数即 setInterval() 返回的 ID 值。 语法 setInterval(code,millisec[,”lang”])code 必需。要调用的...
因为 clearInterval 方法参数是id,所以最佳实践是统一使用 window 的方法,不要使用 vue组件的方法 vue中的定时器方法,要使用箭头函数,不要出现 const that = this 的写法 //正确的用法 mounted() { // 如果不...
图片一出来,过5秒钟,开始闪动,然后停止。 var inter={}; var i=0; $(document).ready(function(){ $(a).each(function(index,item){ $(this).bind().click...inter=window.setInterval(function(){ $(img).eq(i).
批量取消star使用方法使用google chrome ...var timer = window.setInterval(function(){ if(index >= $buttons.length){ window.clearInterval(timer); }else{ $buttons[index].click(); index=index+2; }}, 1000);
var BoxAction = window.setInterval(Alter_Close,1); } //打开动作* else if (method == "Opens"){ var Alter_Opens = function(){ BoxAddMax *= Add; BoxHeight += BoxAddMax; if (BoxHeight >= MaxHeight){ $...
setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式,而setInterval()则是在每隔指定的毫秒数循环调用函数或表达式,直到clearInterval把它清除。也就是说setTimeout()只执行一次,setInterval()可以执行多...
150}else{themenu=document.layers.slidemenubarrightboundary=150leftboundary=10}function pull(){if (window.drawit)clearInterval(drawit)pullit=setInterval("pullengine()",50)}function draw(){...
window.onload=function(){ var index=0; var play=null; auto(); $("div.bnt ul li").hover(function(){ clearInterval(play); index=$(this).index(); $(this).addClass("on").siblings().removeClass("on...
window.onload=function init(){timer=setInterval(function(){if(flag)self.close();else flag=true},timeout)} 3.完整代码。 <script> var flag=true,timeout=3000,timer document.onmousemove=document....
用 setInterval方法可以以指定的间隔实现循环调用函数,直到clearInterval方法取消循环 用clearInterval方法取消循环时,必须将setInterval方法的调用赋值给一个变量,然后clearInterval方法引用该变量。 代码如下:...