更新时间:2021-07-25 04:49:17
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>