Jquery 设置超时函数调用后刷新当前页面
执行Jquery 设置超时函数调用后刷新当前页面,jquery,settimeout,Jquery,Settimeout,执行setTimeout()函数调用后,是否有方法刷新页面 下面是setTimeout函数调用的代码: setTimeout(function(){ $('#alert-success').slideUp('slow').fadeOut(); }, 5000); 试一试 setTimeout(function(){ $('#alert-success').slideUp('slow').fadeOut(function() { window.locatio
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
)
试试下面这个
<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>
此页面将每5秒刷新一次。这是因为我们正在使用“onload”事件来调用我们的函数。我们正在传递值“5000”,它等于5秒
但是,嘿,不要每隔几秒钟就用不必要的页面刷新来打扰你的用户
您也可以使用
window.location.href = window.location.href
脚本重写为
setTimeout(function()
{
$('#alert-success').slideUp('slow').fadeOut();
window.location.href = window.location.href
},5000)
感谢您的回复,我已经从Fabrizio那里找到了解决方案:)
setTimeout(function()
{
$('#alert-success').slideUp('slow').fadeOut();
window.location.href = window.location.href
},5000)