admin管理员组文章数量:1304184
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.
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.
Share Improve this question edited Jan 21, 2011 at 21:01 Daniel Huckstep 5,40810 gold badges42 silver badges56 bronze badges asked Dec 2, 2010 at 17:50 ThewThew 16k19 gold badges61 silver badges102 bronze badges6 Answers
Reset to default 10You should pass the actual function as argument and not the call:
setTimeout(updateimage, 5000);
2 options:
setTimeout("updateimage()", 5000)
or use a function:
setTimeout(function() {
updateimage();
}, 5000);
Try
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);
setTimeout(updateimage(), 5000);
Remove the parenthesis from updateimage, so it is:
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);
本文标签: javascriptTimeout doesn39t workStack Overflow
版权声明:本文标题:javascript - Timeout doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741778870a2397186.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论