摘要:本篇教程介绍了jQuery实战教程 如何实现时间日期三级联动,希望阅读本篇文章以后大家有所收获,帮助大家对jQuery的理解更加深入。
本篇教程介绍了jQuery实战教程 如何实现时间日期三级联动,希望阅读本篇文章以后大家有所收获,帮助大家对jQuery的理解更加深入。
<
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
2
3 <!DOCTYPE html>
4
5 <html xmlns="//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>
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标WEB前端jQuery频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号