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);
在下面试试这个
<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>
您还可以使用
window.location.href = window.location.href
脚本改写为
setTimeout(function()
{
$('#alert-success').slideUp('slow').fadeOut();
window.location.href = window.location.href
},5000)