jquery时间日期三级联动
Posted 懒人起烂命
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery时间日期三级联动相关的知识,希望对你有一定的参考价值。
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> 2 3 <!DOCTYPE html> 4 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 8 <script src="js/jquery-1.7.2.min.js"></script> 9 <title></title> 10 </head> 11 <body> 12 <form id="form1" runat="server"> 13 <div> 14 <asp:DropDownList ID="dr_year" runat="server"></asp:DropDownList>年 15 <asp:DropDownList ID="dr_month" runat="server"></asp:DropDownList>月 16 <asp:DropDownList ID="dr_day" runat="server"></asp:DropDownList>日 17 </div> 18 </form> 19 </body> 20 </html> 21 <script> 22 var days = 0; 23 years(); 24 months(); 25 Days(); 26 var date = new Date(); 27 $("#dr_year").val(date.getFullYear()); 28 $("#dr_month").val((date.getMonth() + 1)); 29 $("#dr_day").val(date.getDate()); 30 $("#dr_year").change(function () { 31 months(); 32 Days(); 33 }); 34 35 $("#dr_month").change(function () { 36 Days(); 37 }); 38 function years() 39 { 40 for(var i=1900;i<=2100;i++) 41 { 42 var str = "<option value=\"" + i + "\">" + i+ "</option>"; 43 $("#dr_year").append(str); 44 } 45 } 46 function months() { 47 $("#dr_month").empty(); 48 for (var i = 1; i <= 12; i++) { 49 var str = "<option value=\"" + i + "\">" + i + "</option>"; 50 $("#dr_month").append(str); 51 } 52 } 53 function Days() { 54 $("#dr_day").empty(); 55 if (parseInt($("#dr_month").val()) == 1 || parseInt($("#dr_month").val()) == 3 || parseInt($("#dr_month").val()) == 5 || parseInt($("#dr_month").val()) == 7 || parseInt($("#dr_month").val()) == 8 || parseInt($("#dr_month").val()) == 10 || parseInt($("#dr_month").val()) == 12) { 56 days = 31; 57 } 58 else if (parseInt($("#dr_month").val()) == 4 || parseInt($("#dr_month").val()) == 6 || parseInt($("#dr_month").val()) == 9 || parseInt($("#dr_month").val()) == 11) { 59 days = 30; 60 } 61 else { 62 if (parseInt($("#dr_year").val()) % 400 == 0 || (parseInt($("#dr_year").val()) % 4 == 0 && parseInt($("#dr_year").val()) % 100 != 0)) { 63 days = 29; 64 } 65 else { 66 days = 28; 67 } 68 } 69 for (var i = 1; i <= days; i++) { 70 var str = "<option value=\"" + i + "\">" + i + "</option>"; 71 $("#dr_day").append(str); 72 } 73 } 74 </script>
以上是关于jquery时间日期三级联动的主要内容,如果未能解决你的问题,请参考以下文章