今晚作业:2012年12月21日“末日倒计时”源码。(可惜不知道怎么在博客显示效果……)

    技术2024-11-22  15

    发现了一点关键地方:月份是从0开始算起的。周数也是,周日为0,周六为6。我在这方面浪费了不少时间,基础知识不足啊= =!

     

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>daoJiShi</title> <mce:style type="text/css"><!-- body { background:#000; color:#fff; } h1 { text-align:center;} .daoJiShi { font-size:50px; } --></mce:style><style type="text/css" mce_bogus="1"> body { background:#000; color:#fff; } h1 { text-align:center;} .daoJiShi { font-size:50px; } </style> <mce:script language="javascript"><!-- function DaoJiShi() { var now = new Date(); var target = new Date(2012,11,21,00,00,00); //PS:月数从0开始算 var days = document.getElementById("days"); var hours = document.getElementById("hours"); var minutes = document.getElementById("minutes"); var seconds = document.getElementById("seconds"); var getDays = Math.floor( (target-now)/1000/60/60/24 ); //获得天数; var getHours = Math.floor( (target-now)/1000/60/60%24 ); //获得小时; var getMinutes = Math.floor( (target-now)/1000/60%60 ); //获得分钟; var getSeconds = Math.floor( (target-now)/1000%60 );//获得秒数; days.innerHTML = " "+ getDays +" "; //输入天数; hours.innerHTML = " "+ getHours +" "; //输入小时; minutes.innerHTML = " "+ getMinutes +" "; //输入分钟; seconds.innerHTML = " "+ getSeconds +" "; //输入秒数; setTimeout("DaoJiShi()",1000); } // --></mce:script> </head> <body οnlοad="DaoJiShi()"> <h1>离2012年12月21日世界末日还有<span class="daoJiShi" id="days"></span>天<span class="daoJiShi" id="hours"> </span>小时<span class="daoJiShi" id="minutes"> </span>分钟<span class="daoJiShi" id="seconds"> </span>秒</h1> </body> </html> 

     

    最新回复(0)