开发者

Calling setInterval from a self-executing function

The following way to call setInterval seems to work in Firefox 3.5 and Chromium 10.0 but not in Firefox 4.

var setInterval;
(function runmenow () {
  setInterval(function () { document.write('hello<br /&g开发者_JAVA技巧t;'); }, 1000);
}());

Firebug tells me that "setInterval is not a function". Why isn't setInterval available in this context?


This (i believe) is because you are setting setInterval as null in that first line.

just do:

//var setInterval; <--remove
(function runmenow () {
  setInterval(function () { document.write('hello<br />'); }, 1000);
}());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜