执行setTimeout()
函数调用后是否有办法刷新页面?
这是setTimeout函数调用的代码:
setTimeout(function(){
$('#alert-success').slideUp('slow').fadeOut();
}, 5000);
答案 0 :(得分:23)
尝试
setTimeout(function(){
$('#alert-success').slideUp('slow').fadeOut(function() {
window.location.reload();
/* or window.location = window.location.href; */
});
}, 5000);
答案 1 :(得分:2)
你可以这样做:
(当您使用.slideUp
时,无需使用.fadeOut
)
setTimeout(function() {
$('#alert-success').slideUp('slow', window.location.reload);
}, 5000);
答案 2 :(得分: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>
答案 3 :(得分:1)
您也可以使用
window.location.href = window.location.href
脚本重写为
setTimeout(function()
{
$('#alert-success').slideUp('slow').fadeOut();
window.location.href = window.location.href
},5000)