DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery入門技巧 >> jQuery時間日期三級聯動(推薦)
jQuery時間日期三級聯動(推薦)
編輯:JQuery入門技巧     

廢話不多說了,直接給大家貼js代碼了,具體代碼如下所述:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script src="js/jquery-1.7.2.min.js"></script>
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <asp:DropDownList ID="dr_year" runat="server"></asp:DropDownList>年
    <asp:DropDownList ID="dr_month" runat="server"></asp:DropDownList>月
    <asp:DropDownList ID="dr_day" runat="server"></asp:DropDownList>日
  </div>
  </form>
</body>
</html>
<script>
  var days = 0;
  years();
  months();
  Days();
  var date = new Date();
  $("#dr_year").val(date.getFullYear());
  $("#dr_month").val((date.getMonth() + 1));
  $("#dr_day").val(date.getDate());
  $("#dr_year").change(function () {
    months();
    Days();
  });
  $("#dr_month").change(function () {
    Days();
  });
  function years()
  {
    for(var i=1900;i<=2100;i++)
    {
      var str = "<option value=\"" + i + "\">" + i+ "</option>";
      $("#dr_year").append(str);
    }
  }
  function months() {
    $("#dr_month").empty();
    for (var i = 1; i <= 12; i++) {
      var str = "<option value=\"" + i + "\">" + i + "</option>";
      $("#dr_month").append(str);
    }
  }
  function Days() {
    $("#dr_day").empty();
    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) {
      days = 31;
    }
    else if (parseInt($("#dr_month").val()) == 4 || parseInt($("#dr_month").val()) == 6 || parseInt($("#dr_month").val()) == 9 || parseInt($("#dr_month").val()) == 11) {
      days = 30;
    }
    else {
      if (parseInt($("#dr_year").val()) % 400 == 0 || (parseInt($("#dr_year").val()) % 4 == 0 && parseInt($("#dr_year").val()) % 100 != 0)) {
        days = 29;
      }
      else {
        days = 28;
      }
    }
    for (var i = 1; i <= days; i++) {
      var str = "<option value=\"" + i + "\">" + i + "</option>";
      $("#dr_day").append(str);
    }
  }
</script>

以上所述是小編給大家分享的jQuery時間日期三級聯動效果,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved