Javascript刷新+倒计时文本 [英] Javascript refresh + countdown text

查看:114
本文介绍了Javascript刷新+倒计时文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标题中使用以下javascript来刷新页面

I am using the following javascript in the header to refresh the page

    <script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
    setTimeout("location.reload(true);",timeoutPeriod);
}
//   -->
</script>

和正文标记

<body onload="JavaScript:timedRefresh(5000);">

我的问题是如何添加显示刷新页面倒计时的文字

My question is how do I add a text showing the countdown to refresh the page

x秒刷新

推荐答案

这是否符合您的需求?

(function countdown(remaining) {
    if(remaining <= 0)
        location.reload(true);
    document.getElementById('countdown').innerHTML = remaining;
    setTimeout(function(){ countdown(remaining - 1); }, 1000);
})(5); // 5 seconds

JSFiddle

这篇关于Javascript刷新+倒计时文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆