<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>三級聯動年月日</title> <meta name="keywords" content="關鍵字列表" /> <meta name="description" content="網頁描述" /> <link rel="stylesheet" type="text/css" href="" /> <script type="text/javascript" src="js/jquery-1.9.1.min.js" ></script> <style> body{padding: 0;margin: 0;} .content{width: 1000px;margin: 50px auto;padding: 0;} </style> </head> <body> <div class="content"> <select id="year"> <option value="0">--請選擇--</option> </select>年 <select id="month"> <option value="0">--請選擇--</option> </select>月 <select id="day"> <option value="0">--請選擇--</option> </select>日 </div> <script> (function(){ function selectFun(eleId,start,end){ for(start;start<=end;start++){ eleId.add(new Option(start,start)); } } var startY=1970; var end=new Date().getFullYear(); var year=document.getElementById("year"); var month=document.getElementById("month"); var day=document.getElementById("day") selectFun(year,startY,end); year.onchange=function(){ month.length=1; day.length = 1; if(this.value!=0){ selectFun(month,1,12); } } month.onchange=function(){ day.length = 1; var value=this.value; if(value!=0){ if(value==2){ console.log('2----'); if(ifRunYear(year.value)){ selectFun(day,1,29); }else{ selectFun(day,1,28); } }else if(value==4||value==6||value==9||value==11){ console.log('30----'); selectFun(day,1,30); }else{ console.log('31----'); selectFun(day,1,31); } } } function ifRunYear(year){ return (year% 4 == 0 && year % 100 != 0) || (year % 100 == 0 && year % 400 == 0); } })(); </script> </body> </html>