jQuery 设置超时函数调用后刷新当前页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12173800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
refresh current page after set timeout function call
提问by Arish
Is there a way to refresh page after setTimeout()
function call is executed?
有没有办法在setTimeout()
函数调用执行后刷新页面?
here is the code of setTimeout function call:
这是 setTimeout 函数调用的代码:
setTimeout(function(){
$('#alert-success').slideUp('slow').fadeOut();
}, 5000);
回答by Fabrizio Calderan
try with
尝试
setTimeout(function(){
$('#alert-success').slideUp('slow').fadeOut(function() {
window.location.reload();
/* or window.location = window.location.href; */
});
}, 5000);
回答by xdazz
You could do like this:
(when you use .slideUp
, there is no need to use .fadeOut
)
你可以这样做:(当你使用时.slideUp
,没有必要使用.fadeOut
)
setTimeout(function() {
$('#alert-success').slideUp('slow', window.location.reload);
}, 5000);
回答by Sathish
Try this below
下面试试这个
<html>
<head>
<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}
// -->
</script>
</head>
<body onload="JavaScript:timedRefresh(5000);">
<p>This page will refresh every 5 seconds. This is because we're using the 'onload' event to call our function. We are passing in the value '5000', which equals 5 seconds.</p>
<p>But hey, try not to annoy your users too much with unnecessary page refreshes every few seconds!</p>
</body>
</html>
回答by Champ
You can also Use
您还可以使用
window.location.href = window.location.href
Script rewritten as
脚本重写为
setTimeout(function()
{
$('#alert-success').slideUp('slow').fadeOut();
window.location.href = window.location.href
},5000)