js时间日期的三级联动

Posted 游称

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js时间日期的三级联动相关的知识,希望对你有一定的参考价值。

aspx:

<div style="width:70px;float:left;">生日</div>
            <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList><asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList><asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList>日

js:

<script>
  //年份变动的事件 document.getElementById("DropDownList1").onchange = function () { var mon = document.getElementById("DropDownList2"); var day = document.getElementById("DropDownList3"); if (mon.value == "2") { if (this.value % 4 == 0 && this.value % 100 != 0 || this.value % 400 == 0) { day.options.length = 0; for (var i = 1; i < 30; i++) { var op = document.createElement("option"); op.value = i; op.innerhtml = i; day.appendChild(op); } } else { day.options.length = 0; for (var i = 1; i < 29; i++) { var op = document.createElement("option"); op.value = i; op.innerHTML = i; day.appendChild(op); } } } else if (mon.value == "1" || mon.value == "3" || mon.value == "5" || mon.value == "7" || mon.value == "8" || mon.value == "10" || mon.value == "12") { day.options.length = 0; for (var i = 1; i <= 31; i++) { var op = document.createElement("option"); op.value = i; op.innerHTML = i; day.appendChild(op); } } else { day.options.length = 0; for (var i = 1; i <= 30; i++) { var op = document.createElement("option"); op.value = i; op.innerHTML = i; day.appendChild(op); } } }   //月变动的事件 document.getElementById("DropDownList2").onchange = function () { var day = document.getElementById("DropDownList3"); var year = document.getElementById("DropDownList1"); if (this.value == "2") { if (year.value % 4 == 0 && year.value % 100 != 0 || year.value % 400 == 0) { day.options.length = 0; for (var i = 1; i < 30; i++) { var op = document.createElement("option"); op.value = i; op.innerHTML = i; day.appendChild(op); } } else { day.options.length = 0; for (var i = 1; i < 29; i++) { var op = document.createElement("option"); op.value = i; op.innerHTML = i; day.appendChild(op); } } } else if (this.value == "1" || this.value == "3" || this.value == "5" || this.value == "7" || this.value == "8" || this.value == "10" || this.value == "12") { day.options.length = 0; for (var i = 1; i <= 31; i++) { var op = document.createElement("option"); op.value = i; op.innerHTML = i; day.appendChild(op); } } else { day.options.length = 0; for (var i = 1; i <= 30; i++) { var op = document.createElement("option"); op.value = i; op.innerHTML = i; day.appendChild(op); } } } </script>

后台cs:

if (!IsPostBack)
        {
            for (int i = DateTime.Now.Year; i >= 1900; i--)
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                DropDownList1.Items.Add(li);
            }
            for (int i = 1; i < 13; i++)
            {
                DropDownList2.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
            for (int i = 1; i < 31; i++)
            {
                DropDownList3.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
        
        
        }

 


以上是关于js时间日期的三级联动的主要内容,如果未能解决你的问题,请参考以下文章

H5个性三级联动日期插件

python-Web-django-时间插件-三级联动

js之select三级联动

jquery时间日期三级联动

js三级联动(求思路更好)

js三级联动