JS automatically redirects to the next n seconds.
The examples in this article share two methods for automatically redirecting JavaScript code to a next n seconds for your reference. The specific content is as follows:
First useSetInterval:
$(function () { setInterval(ChangeTime, 1000); }); function ChangeTime() { var time; time = $("#time").text(); time = parseInt(time); time--; if (time <= 0) { window.location.href = "/Home/Index"; } else { $("#time").text(time); } }
Second, use SetTimeout:
$ (Function () {setTimeout (ChangeTime, 1000) ;}); function ChangeTime () {var time; time =$ ("# time "). text (); time = parseInt (time); time --; if (time <= 0) {window. location. href = "/Home/Index";} else {$ ("# time "). text (time); setTimeout (ChangeTime, 1000) ;}< div> the page you accessed encountered an exception, <span id = "time"> 5 </span> automatically jumps to the homepage in seconds </div>
The above is all the content of this article, and I hope it will help you learn javascript programming.