5秒后跳转效果(setInterval/SetTimeOut)

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

5秒后跳转效果(setInterval/SetTimeOut)

  2020-05-13 我要评论
setInterval版
复制代码 代码如下:

$(function () {
setInterval(function () {
var time = $("#time").text();
time = parseInt(time);
time--;
if (time >0) {
$("#time").text(time);
} else {
window.location = $("#url").attr("href");
}
}, 1000);
});

SetTimeOut版
复制代码 代码如下:

<script type="text/javascript">
window.onload = function () {
setTimeout(changeTime, 1000);
}
function changeTime() {
var time = document.getElementById("time").innerHTML;
time = parseInt(time);
time--;
if (time <= 0) {
var url = document.getElementById("url").href;
window.location = url;
} else {
document.getElementById("time").innerHTML= time;
setTimeout(changeTime, 1000);
}
}
</script>

html
复制代码 代码如下:

<span style="font-size: 18px; color: Red" id="time">5</span>秒钟以后跳转到 <a href="<%=this.url %>"

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们