国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > JS > 正文

基于JavaScript實(shí)現(xiàn)自動(dòng)更新倒計(jì)時(shí)效果

2024-05-06 16:33:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

實(shí)現(xiàn)倒計(jì)時(shí)效果需要掌握js中的兩個(gè)知識(shí)點(diǎn):
1、setTimeout函數(shù) 每隔1秒鐘更新秒鐘時(shí)間
2、Date對(duì)象 計(jì)算時(shí)間差

下面貼出 元旦倒計(jì)時(shí)代碼

<!DOCTYPE html><html> <head> <title>example.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <script> //定義計(jì)時(shí)器,每隔1秒鐘調(diào)用timer函數(shù) var timerCount= window.setTimeout("timer()",1000); function timer(){ var date=new Date("2017","1","1","0","0","0"); var deadlineTime=date.getTime(); var nowDate=new Date(); var nowTime=nowDate.getTime(); var distTime=deadlineTime-nowTime; //判斷是否到達(dá)時(shí)間期限 if(distTime>0){ var d=Math.floor(distTime/1000/3600/24); var h=Math.floor(distTime/1000/3600%24); var m=Math.floor(distTime/1000/60%60); var s=Math.floor(distTime/1000%60); var str="距離2017年元旦還有"+d+"天"+h+"時(shí)"+m+"分"+s+"秒"; document.getElementById("timeout").innerHTML=str; timerCount= window.setTimeout("timer()",1000);  } else{ //到達(dá)時(shí)間期限的時(shí)候清楚計(jì)時(shí)器; window.clearTimeout(timerCount); alert("時(shí)間已到"); } } </script> </head> <body> <p id="timeout"> </p></html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到JavaScript/Ajax教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 双辽市| 越西县| 江都市| 开平市| 佛坪县| 天全县| 吉林市| 靖宇县| 定州市| 天峻县| 正安县| 新密市| 手机| 屏东市| 正宁县| 昭觉县| 大连市| 桐乡市| 潼关县| 新河县| 兰州市| 黔南| 吴江市| 兴安盟| 温宿县| 金阳县| 公主岭市| 敖汉旗| 望谟县| 安岳县| 班玛县| 青冈县| 曲水县| 公安县| 泾阳县| 新晃| 武穴市| 宾川县| 响水县| 蕉岭县| 东乌珠穆沁旗|