<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>倒计时牌-->献给祖国60大庆</title> </head> <!--2009年9月25日写于杭州 --> <body onload="tai()" bgcolor="teal"> <center> <font color="black" size="6" face="楷体_GB2312">千山牌倒计时</font> <br><br> 选择年月日: <select id = "t_year" name = "t_year" onchange="change()"></select>年 <select id = "t_month" name = "t_month" onchange="change()"></select>月 <select id = "t_day" name = "t_day"></select>日 <input type = "button" value="确定" onclick="wu()"> <br><br> 距离:<span id="target"></span> 还有:<br> <hr color="#005B5B"> <br><br><br><br> <font style="font-size: 100px" mce_style="font-size: 100px"> <span style="color: fuchsia" mce_style="color: fuchsia" id="day"></span>天 <span style="color: fuchsia" mce_style="color: fuchsia" id="hour"></span>小时 <span style="color: fuchsia" mce_style="color: fuchsia" id="minute"></span>分 <span style="color: fuchsia" mce_style="color: fuchsia" id="second"></span>秒 </font> <br><br><br><br><br><br><br> <hr color="#005B5B"> The time is so quickly that we should must treasure it. </center> </body> <script type="text/javascript"> //目标年月日 var y = 2009; var m = 10; var d = 1; //目标日期显示 document.getElementById('target').innerHTML = y + "年" + m + "月" + d + "日"; //下拉框赋值 this.setSelect('t_year',2009,2019); this.setSelect('t_month',1,12); this.setSelect('t_day',1,31); //选中十月 document.getElementById('t_month').options[9].selected = 'selected'; //倒计时计算 function tai(){ var date1 = new Date(y,m-1,d); var date2 = new Date(); var time = date1.getTime()-date2.getTime(); var sec = parseInt(time/1000); var day=Math.floor(sec/(60*60*24)); var hour=Math.floor((sec-day*24*60*60)/3600); var minute=Math.floor((sec-day*24*60*60-hour*3600)/60); var second=Math.floor(sec-day*24*60*60-hour*3600-minute*60); document.getElementById('day').innerHTML = day; document.getElementById('hour').innerHTML = hour; document.getElementById('minute').innerHTML = minute; document.getElementById('second').innerHTML = second; setTimeout("tai()",1000); } //给下拉框赋值 function setSelect(id,first,last){ var select = document.getElementById(id); for(var i=select.length-1;i>=0;i--){ select.remove(i); } for(var j = first; j <= last; j++){ var newoption = document.createElement('option'); newoption.value = j; newoption.text = j; select.add(newoption); } } //更新目标年月日 function wu(){ //目标年月日 y = document.all.t_year.value; m = document.all.t_month.value; d = document.all.t_day.value; //目标日期显示 document.getElementById('target').innerHTML = y + "年" + m + "月" + d + "日"; } //年月下拉框change事件 function change(){ var yyyy = document.all.t_year.value; var mm = document.all.t_month.value; var dCount = this.getNumber(yyyy,mm); this.setSelect("t_day",1,dCount); } //根据年月求天数 function getNumber(yyyy,mm){ var number=0; switch (parseInt(mm)) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: number = 31; break; case 4: case 6: case 9: case 11: number = 30; break; default: if(yyyy%400==0||(yyyy%4==0&&yyyy%100!=0)){ number = 29; }else{ number = 28; } } return number; } </script> </html>