如何在JavaScript或jQuery中刷新或重新加载带有超时的页面 [英] How to refresh or reload a page with timeout in javascript or jquery

查看:113
本文介绍了如何在JavaScript或jQuery中刷新或重新加载带有超时的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在

  • 特定班级可见 或
  • 未找到img
  • a specific class is visible or
  • img is not found

我发现了这个 https://stackoverflow.com/a/14787543/7051635 ,但是没有超时和何时我在一个未找到的门前,什么也没发生.

i found this https://stackoverflow.com/a/14787543/7051635 but there is no timeout and when i'm in front of an omg not found, nothing happened.

推荐答案

使用

Use the setTimeout() global method to create a timer. This will reload the page after 5000 milliseconds (5 seconds):

 setTimeout(function(){ location.reload(); }, 5000);

此代码可以添加到您需要的任何事件中.因此,例如:

This code can be added to any event you need it to. So, for example:

var theDiv = document.querySelector("div");

// When the div is clicked, wait 5 seconds and then hide it.
theDiv.addEventListener("click", function(){
   setTimeout(function(){ 
     theDiv.classList.add("hide"); 
   }, 5000);
});

.hide { display:none; }

<div>Now you see me.</div>

这篇关于如何在JavaScript或jQuery中刷新或重新加载带有超时的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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