setInterval Method--------------------------------------------------------------------------------Evaluates an expression each time a specified number of milliseconds has elapsed.SyntaxiTimerID = window.setInterval(vCode, iMilliSeconds [, sLanguage])
ParametersvCode Required. Variant that specifies a function pointer or string that indicates the code to be executed when the specified interval has elapsed.
iMilliSeconds Required. Integer爐hat specifies the number of milliseconds.
sLanguage Optional. String爐hat specifies any one of the possible values for the LANGUAGE attribute. Return ValueInteger. Returns an identifier that cancels the timer with the clearInterval method. ResThe setInterval method continuously evaluates the specified expression until the timer is removed with the clearInterval method. In versions earlier than Microsoft?Internet Explorer 5, the first argument of setInterval must be a string. Evaluation of the string is deferred until the specified interval elapses.As of Internet Explorer 5, the first argument of setInterval can be passed as a string or as a function pointer.To pass a function as a string, be sure to suffix the function name with parentheses.window.setInterval("someFunction()", 5000);When passing a function pointer, do not to include the parentheses. window.setInterval(someFunction, 5000);Include the parentheses to have the function evaluated immediately before setInterval is called. The result of the function is passed to setInterval rather than to the function. To retrieve a function pointer, use the code shown in the following example:function callback()
{
alert("callback");
}function callback2()
{
alert("callback2");
}function chooseCallback(iChoice)
{
switch (iChoice)
{
case 0:
return callback;
case 1:
return callback2;
default:
return "";
}
}// if i is 0, callback is invoked after 5 seconds
// if i is 1, callback2 is invoked
// otherwise, the timer is not set
window.setInterval(chooseCallback(i), 5000);ExampleThis example uses the setInterval method to create a DHTML clock. A variable is assigned to the interval, and can be used as a reference to stop the interval using the clearInterval method.var oInterval = "";function fnStartInterval(){
oInterval = window.setInterval("fnRecycle()",1000);
}
function fnRecycle(){
// Code to display hours, minutes, and seconds.
}
ParametersvCode Required. Variant that specifies a function pointer or string that indicates the code to be executed when the specified interval has elapsed.
iMilliSeconds Required. Integer爐hat specifies the number of milliseconds.
sLanguage Optional. String爐hat specifies any one of the possible values for the LANGUAGE attribute. Return ValueInteger. Returns an identifier that cancels the timer with the clearInterval method. ResThe setInterval method continuously evaluates the specified expression until the timer is removed with the clearInterval method. In versions earlier than Microsoft?Internet Explorer 5, the first argument of setInterval must be a string. Evaluation of the string is deferred until the specified interval elapses.As of Internet Explorer 5, the first argument of setInterval can be passed as a string or as a function pointer.To pass a function as a string, be sure to suffix the function name with parentheses.window.setInterval("someFunction()", 5000);When passing a function pointer, do not to include the parentheses. window.setInterval(someFunction, 5000);Include the parentheses to have the function evaluated immediately before setInterval is called. The result of the function is passed to setInterval rather than to the function. To retrieve a function pointer, use the code shown in the following example:function callback()
{
alert("callback");
}function callback2()
{
alert("callback2");
}function chooseCallback(iChoice)
{
switch (iChoice)
{
case 0:
return callback;
case 1:
return callback2;
default:
return "";
}
}// if i is 0, callback is invoked after 5 seconds
// if i is 1, callback2 is invoked
// otherwise, the timer is not set
window.setInterval(chooseCallback(i), 5000);ExampleThis example uses the setInterval method to create a DHTML clock. A variable is assigned to the interval, and can be used as a reference to stop the interval using the clearInterval method.var oInterval = "";function fnStartInterval(){
oInterval = window.setInterval("fnRecycle()",1000);
}
function fnRecycle(){
// Code to display hours, minutes, and seconds.
}
解决方案 »
- 求javaScript 数字排序代码
- 以下代码为什么不能成功?用到jquery
- table对象 的 appendChild()的问题
- hookee好!以下这段js代码怎么在firefox浏览器下不正常?IE下正确的,请问怎么兼容所有浏览器?!
- 这个效果怎么实现 谢谢
- 如何通过IE全屏显示
- 请问:javascript中用new ActiveXObject("")方式创建的控件,如何在页面上把控件显示出来
- 求助:在一个时间段中除去双休日的javascript代码
- 页面传入ID,打开后怎么让下拉菜单的值显示为selected
- 怎样在后台加载网页,然后显示
- 项目吃紧,特100分求修改一段代码,基本样式都已经有了(支持手工输入的下拉框).
- 在线等——如何屏蔽弹出窗口的最大化按钮?
window.setTimeout("yourFunction()", 5000);如果每隔5秒就循环执行:
window.setInterval("yourFunction()", 5000);
function b(){}
//下面是触发函数
function A()
{
setTimeout("b()",5000);
}
A();//运行A(),5秒后,b()将被运行...
alert("1");
setTimeout(delay1,5000)
function delay1(){
//5秒后运行
alert("5");
}
}