详情页

javascript实现5秒倒计时并跳转功能

时间:2023年11月24日

编辑:佚名

javascript实现实现5秒倒计时并跳转功能秒倒计时并跳转功能
本文实例为大家分享了js实现5秒倒计时并跳转功能的具体代码,供大家参考,具体内容如下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>倒计时五秒</title>
<script>
//使用匿名函数方法
function countDown(){
var time = document.getElementById("Time");
//alert(time.innerHTML);
//获取到id为time标签中的内容,现进行判断
if(time.innerHTML == 0){
//等于0时清除计时
window.location.href="https://www.baidu.com" rel="external nofollow" ;
}else{
time.innerHTML = time.innerHTML-1;
}
}
//1000毫秒调用一次
window.setInterval("countDown()",1000);
</script>
<style>
#Time,#p{
font-size: 100px;
text-align: center;
}
</style>
</head>
<body>
<p id="Time">5</p>
</body>
</html>
再为大家分享两段:
jQuery实现5秒倒计时
<script src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
var i=5;
$(function(){
setTimeout(function(){
window.location.href='${ctx}/';
},5000);//5秒后返回首页
after();
});
//自动刷新页面上的时间
function after(){
$("#time").empty().append(i);
i=i-1;
setTimeout(function(){
after();
},1000);
}
</script>
点击按钮出现5秒倒计时js代码
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js倒计时测试无标题文档</title>
<script type="text/javascript" src="js/jquery.js"></script>
</head> 
<body> <input type="button" id="btn" value="免费获取验证码" onclick="settime(this)" /> 
<script type="text/javascript"> 
var countdown=5; 
function settime(val) { 
if (countdown == 0) { 
val.removeAttribute("disabled"); 
val.value="免费获取验证码"; 
countdown = 6;
return;

else { 
val.setAttribute("disabled", true); val.value="重新发送(" + countdown + ")"; 
countdown--; 

setTimeout(function() { settime(val) },1000) } 
</script> 
</body> 
</html>
相关文章
猜你需要