超时不起作用
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您应该传递实际函数作为参数而不是调用:
You should pass the actual function as argument and not the call:
2 个选项:
或使用函数:
2 options:
or use a function:
尝试
setTimeout('updateimage()', 5000);
Try
setTimeout('updateimage()', 5000);
根据微软文档此处参数必须是函数指针或字符串。所以下面的两个扭臀动作都会起作用。
方法1
方法2
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
Method 2
把 updateimage 中的括号去掉,就是:
Remove the parenthesis from updateimage, so it is:
正如其他人所说,你称之为错误的。
您所拥有的内容:
执行时会将
updateImage()
的结果传递给setTimeout()
调用。由于您的函数没有返回值,因此您实际上是在说:通过函数名称传递函数,就好像它是该名称的变量一样,确实如此。
As others have stated you are calling it wrong.
What you have there:
When executed this will pass the result of
updateImage()
to thesetTimeout()
call. As your function returns no value, you are in effect actually saying:Pass the function by its name, as if it were a variable of that name, which indeed it is.