6

setTimeout()执行函数调用后有没有办法刷新页面?

这是 setTimeout 函数调用的代码:

setTimeout(function(){
     $('#alert-success').slideUp('slow').fadeOut();
}, 5000);
4

4 回答 4

25

尝试

setTimeout(function(){
     $('#alert-success').slideUp('slow').fadeOut(function() {
         window.location.reload();
         /* or window.location = window.location.href; */
     });
}, 5000);
于 2012-08-29T08:34:47.253 回答
2

您可以这样做:(当您使用 时.slideUp,无需使用.fadeOut

setTimeout(function() {
   $('#alert-success').slideUp('slow', window.location.reload);
}, 5000);
于 2012-08-29T08:35:52.167 回答
1

在下面试试这个

<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>
于 2012-08-29T08:37:03.287 回答
1

您还可以使用

window.location.href = window.location.href

脚本改写为

setTimeout(function()
{

    $('#alert-success').slideUp('slow').fadeOut();
    window.location.href = window.location.href

},5000)
于 2012-08-29T08:44:51.017 回答