超时不起作用

发布于 2024-10-06 01:57:43 字数 233 浏览 1 评论 0原文

function updateimage(){
 $("#fileimg").attr("src","secondimage.jpg");
 $('#fileimg').fadeIn('slow');
}
setTimeout(updateimage(), 5000);

这是我尝试过的代码。它是每 5 秒重新加载图像的代码。但这不起作用。我在 IE 中收到此错误:参数无效 你们都可以帮我吗?谢谢。

function updateimage(){
 $("#fileimg").attr("src","secondimage.jpg");
 $('#fileimg').fadeIn('slow');
}
setTimeout(updateimage(), 5000);

This is the code i tried. Its a code to reload the image every 5 seconds. But it doesn't work. I get this error in IE: Invalid argument
Can y'all help me? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

雪若未夕 2024-10-13 01:57:43

您应该传递实际函数作为参数而不是调用:

setTimeout(updateimage, 5000);

You should pass the actual function as argument and not the call:

setTimeout(updateimage, 5000);
伴我老 2024-10-13 01:57:43

2 个选项:

setTimeout("updateimage()", 5000)  

或使用函数:

setTimeout(function() {
        updateimage();
}, 5000);

2 options:

setTimeout("updateimage()", 5000)  

or use a function:

setTimeout(function() {
        updateimage();
}, 5000);
妄断弥空 2024-10-13 01:57:43

尝试

setTimeout('updateimage()', 5000);

Try

setTimeout('updateimage()', 5000);

旧情别恋 2024-10-13 01:57:43

根据微软文档此处参数必须是函数指针或字符串。所以下面的两个扭臀动作都会起作用。

方法1

setTimeout(updateimage, 5000);

方法2

setTimeout("updateimage", 5000);

According to the microsoft documentation here it the parameter has to be either a function pointer or a string. So both the twerks below will work.

Method 1

setTimeout(updateimage, 5000);

Method 2

setTimeout("updateimage", 5000);
樱花落人离去 2024-10-13 01:57:43
setTimeout(updateimage(), 5000);

把 updateimage 中的括号去掉,就是:

setTimeout(updateimage, 5000);
setTimeout(updateimage(), 5000);

Remove the parenthesis from updateimage, so it is:

setTimeout(updateimage, 5000);
狼性发作 2024-10-13 01:57:43

正如其他人所说,你称之为错误的。

您所拥有的内容:

function updateimage(){
 $("#fileimg").attr("src","secondimage.jpg");
 $('#fileimg').fadeIn('slow');
}

setTimeout(updateimage(), 5000);

执行时会将 updateImage()结果传递给 setTimeout() 调用。由于您的函数没有返回值,因此您实际上是在说:

setTimeout(null, 5000);

通过函数名称传递函数,就好像它是该名称的变量一样,确实如此。

setTimeout(updateimage, 5000);

As others have stated you are calling it wrong.

What you have there:

function updateimage(){
 $("#fileimg").attr("src","secondimage.jpg");
 $('#fileimg').fadeIn('slow');
}

setTimeout(updateimage(), 5000);

When executed this will pass the result of updateImage() to the setTimeout() call. As your function returns no value, you are in effect actually saying:

setTimeout(null, 5000);

Pass the function by its name, as if it were a variable of that name, which indeed it is.

setTimeout(updateimage, 5000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文