jquery实现的年月日三级联动
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JQuery实例 - 生成年月日</title> <meta http-equiv="content-type" content="text/html; charset=gbk"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script type="text/javascript"> $(function () { var $day = $("#day"), $month = $("#month"), $year = $("#year"); <!--出始化年--> var dDate = new Date(), dCurYear = dDate.getFullYear(), str = ""; for (var i = dCurYear - 100; i < dCurYear + 1; i++) { if (i == dCurYear) { str = "<option value=" + i + " selected=true>" + i + "</option>"; } else { str = "<option value=" + i + ">" + i + "</option>"; } $year.append(str); } <!--出始化月--> for (var i = 1; i <= 12; i++) { if (i == (dDate.getMonth() + 1)) { str = "<option value=" + i + " selected=true>" + i + "</option>"; } else { str = "<option value=" + i + ">" + i + "</option>"; } $month.append(str); } <!--调用函数出始化日--> TUpdateCal($year.val(), $month.val()); $("#year,#month").bind("change", function(){ TUpdateCal($year.val(),$month.val()); }); }); <!--根据年月获取当月最大天数--> function TGetDaysInMonth(iMonth, iYear) { var dPrevDate = new Date(iYear, iMonth, 0); return dPrevDate.getDate(); } function TUpdateCal(iYear, iMonth) { var dDate = new Date(), daysInMonth = TGetDaysInMonth(iMonth, iYear), str = ""; $("#day").empty(); for (var d = 1; d <= parseInt(daysInMonth); d++) { if (d == dDate.getDate()) { str = "<option value=" + d + " selected=true>" + d + "</option>"; } else { str = "<option value=" + d + ">" + d + "</option>"; } $("#day").append(str); } } </script> </head> <body> <form name="ymd"> <select id="year"></select>年 <select id="month"></select>月 <select id="day"></select>日 </form> </body> </html>
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17