javascript實現(xiàn)5秒倒計時并跳轉(zhuǎn)功能
更新時間:2019年06月20日 11:23:03 作者:lzpwzy
這篇文章主要為大家詳細介紹了javascript實現(xiàn)5秒倒計時并跳轉(zhuǎn)功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(xiàn)5秒倒計時并跳轉(zhuǎn)功能的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>倒計時五秒</title> <script> //使用匿名函數(shù)方法 function countDown(){ var time = document.getElementById("Time"); //alert(time.innerHTML); //獲取到id為time標簽中的內(nèi)容,現(xiàn)進行判斷 if(time.innerHTML == 0){ //等于0時清除計時 window.location. rel="external nofollow" ; }else{ time.innerHTML = time.innerHTML-1; } } //1000毫秒調(diào)用一次 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實現(xiàn)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>
點擊按鈕出現(xiàn)5秒倒計時js代碼
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</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.setAttribute("disabled", true); val.value="重新發(fā)送(" + countdown + ")"; countdown--; }else { val.removeAttribute("disabled"); val.value="免費獲取驗證碼"; countdown = 5; return;//避免無限循環(huán) } setTimeout(function() { settime(val) },1000) } </script> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JavaScript中的函數(shù)申明、函數(shù)表達式、箭頭函數(shù)
js中的函數(shù)可以通過幾種方式創(chuàng)建,具體創(chuàng)建方法通過實例代碼給大家介紹的非常詳細,文中通過例子給大家介紹了函數(shù)聲明和表達式之間的差別,感興趣的朋友跟隨小編一起看看吧2019-12-12