如何让程序等待?

qdpb 2003-10-21 07:59:56
有一个循环体,我想让他5秒循环一次,我知道用settimeout可以实现等待,但是要传递很多参数才可以。请问又没其他办法?
var iii=0;
for (iii=0;i<10;i++)
{

onclick_op3043(form1,menuID,product_id);

} return true;
...全文
36 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qdpb 2003-11-09
  • 打赏
  • 举报
回复
up
qdpb 2003-10-21
  • 打赏
  • 举报
回复
可是调用("fnRecycle()"无法使用参数啊
zhfkiller 2003-10-21
  • 打赏
  • 举报
回复
setInterval Method

--------------------------------------------------------------------------------

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

Syntax

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. Integer爐hat specifies the number of milliseconds.
sLanguage Optional. String爐hat 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 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);

Example

This 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.
}
fyzeng 2003-10-21
  • 打赏
  • 举报
回复
用setInterval

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧