5秒后跳转效果(setInterval/SetTimeOut)
时间:2020-10-20 15:14:55|栏目:JavaScript代码|点击: 次
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 %>"
复制代码 代码如下:
$(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 %>"
上一篇:js基本ajax写法示例代码
栏 目:JavaScript代码
本文标题:5秒后跳转效果(setInterval/SetTimeOut)
本文地址:http://www.codeinn.net/misctech/14125.html