HBCMS更多的中文手册参考:

setInterval Method

DHTML文档教程

Evaluates an expression each time a specified number of milliseconds has elapsed.

dhtml语法

iTimerID = window.setInterval(vCode, iMilliSeconds [, sLanguage])

Parameters

vCode Required. Variant that specifies a function pointer or string that indicates the code to be executed when the specified interval has elapsed.
iMilliSeconds Required. Integerthat specifies the number of milliseconds.
sLanguage Optional. Stringthat specifies any one of the possible values for the language attribute.

return value

integer. returns an identifier that cancels the timer with the clearinterval method.

remarks

the 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 include the parentheses.

window.setinterval(somefunction, 5000);

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);

When you use the setInterval method with Introduction to DHTML Behaviors, the value of vCode should be a function pointer to call a function within the HTML Component (HTC) file or a string to call a function in the primary document.

DHTML代码范例

This example uses the setInterval method to create a Dynamic HTML(动态HTML,即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.
}
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

是否符合公共标准

There is no public standard that applies to this method.

Applies To

window

更多语法参考

clearinterval, settimeout, setTimeout