setTimeout()
函數調用執行後有沒有辦法刷新頁面?設置超時後刷新當前頁面功能調用
這裏是setTimeout函數調用的代碼:
setTimeout(function(){
$('#alert-success').slideUp('slow').fadeOut();
}, 5000);
setTimeout()
函數調用執行後有沒有辦法刷新頁面?設置超時後刷新當前頁面功能調用
這裏是setTimeout函數調用的代碼:
setTimeout(function(){
$('#alert-success').slideUp('slow').fadeOut();
}, 5000);
嘗試
setTimeout(function(){
$('#alert-success').slideUp('slow').fadeOut(function() {
window.location.reload();
/* or window.location = window.location.href; */
});
}, 5000);
你可以這樣做: (當你使用.slideUp
,就沒有必要使用.fadeOut
)
setTimeout(function() {
$('#alert-success').slideUp('slow', window.location.reload);
}, 5000);
謝謝xdazz會記住它。 – Arish
下面試試
<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>
感謝您的回覆,我已經找到了Fabrizio的解決方案:) – Arish
您還可以使用
window.location.href = window.location.href
劇本改寫爲
setTimeout(function()
{
$('#alert-success').slideUp('slow').fadeOut();
window.location.href = window.location.href
},5000)
在編,但你打我:) – Flash
由於一噸快速響應,法布里奇奧現在就解決了。 – Arish