zoukankan      html  css  js  c++  java
  • 年月日三级菜单 jquery

    需要后太类来处理出示化时候对年月日的绑定 网上看到很多年月日三级下拉菜单的 但是在后台只能获取到年月的值 天的值是获取不到的 我的这个可以拿到

    前台代码

       <div style=" 200px; border-color: #FF0000;">
                                            <select name="year0" id="year" runat="server">
                                            </select>年
                                            <select name="month" id="month0" runat="server">
                                            </select>月
                                            <select name="days" onchange="setValue(this.value)" id="days0" runat="server">
                                            </select>日
       </div>

    还需要一个 <asp:HiddenField ID="HidDD" runat="server" />

    需要引用的文件


        <script src="../JS/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>

    如果没有这个包那你只能自己下载了 这里不能上传

    <script type="text/ecmascript">

            $(document).ready(function() {
                var day = $("#days0").val();
                var yearstr = $("#year option:selected").val();
                var monthstr = $("#month0 option:selected").text();
                var str = "";
                if (monthstr == 2) {
                    $("#days0").empty();
                    if (yearstr % 100 != 0 && yearstr % 4 == 0 || yearstr % 100 == 0 && yearstr % 400 == 0) {
                        for (var i = 1; i < 30; i++) {
                            str += "<option value=" + i + "> " + i + "</option>";
                        }
                    } else {
                        for (var i = 1; i < 29; i++) {
                            str += "<option value=" + i + "> " + i + "</option>";
                        }
                    }
                    $(str).appendTo("#days0");
                };

                $("#days0").val(day);//这句很关键的
                $("#hidDD").val(day);//这句也是

                $("#month0").change(function() {
                    var yearstr = $("#year option:selected").val();
                    var monthstr = $("#month0 option:selected").text();
                    var str = "";

                    if (monthstr == '1' || monthstr == '3' || monthstr == '5' || monthstr == '7' || monthstr == '8' || monthstr == '10' || monthstr == '12') {
                        $("#days0").empty();
                        for (var i = 1; i < 32; i++) {
                            str += "<option value=" + i + "> " + i + "</option>";
                        }
                        $(str).appendTo("#days0");
                    } else if (monthstr == 2) {
                        $("#days0").empty();
                        if (yearstr % 100 != 0 && yearstr % 4 == 0 || yearstr % 100 == 0 && yearstr % 400 == 0) {
                            for (var i = 1; i < 30; i++) {
                                str += "<option value=" + i + "> " + i + "</option>";
                            }
                        } else {
                            for (var i = 1; i < 29; i++) {
                                str += "<option value=" + i + "> " + i + "</option>";
                            }
                        }
                        $(str).appendTo("#days0");
                    } else {
                        $("#days0").empty();
                        for (var i = 1; i < 31; i++) {
                            str += "<option value=" + i + "> " + i + "</option>";
                        }
                        $(str).appendTo("#days0");
                    }
                });
                $("#year").change(function() {
                    var yearstr = $("#year option:selected").val();
                    var monthstr = $("#month0 option:selected").text();
                    var str = "";
                    if (monthstr == 2) {
                        $("#days0").empty();
                        if (yearstr % 100 != 0 && yearstr % 4 == 0 || yearstr % 100 == 0 && yearstr % 400 == 0) {
                            for (var i = 1; i < 30; i++) {
                                str += "<option value=" + i + "> " + i + "</option>";
                            }
                        } else {
                            for (var i = 1; i < 29; i++) {
                                str += "<option value=" + i + "> " + i + "</option>";
                            }
                        }
                        $(str).appendTo("#days0");
                    }
                });
            });
            function setValue(val) {
                $("#HidDD").val(val);
            }
        </script>

    后台代码

    private void BindDATE()
            {
                for (int i = 1980; i < System.DateTime.Now.Year; i++)
                {
                    string text = i.ToString();
                    string value = i.ToString();
                    this.year.Items.Add(new ListItem(text, value));
                }
                for (int i = 1; i < 13; i++)
                {
                    string text = i.ToString();
                    string value = i.ToString();
                    this.month0.Items.Add(new ListItem(text, value));
                }

                for (int i = 1; i < 32; i++)
                {
                    string text = i.ToString();
                    string value = i.ToString();
                    this.days0.Items.Add(new ListItem(text, value));
                }
            }

    日是绑上去的 31天 有人可能说这样不对 没问题 天数的计算在js里面已经处理了 是根据年月来计算的

  • 相关阅读:
    Django ——Timezone 处理
    orm
    MySql系列之初识
    python并发编程之IO模型
    并发编程之协程
    GIL解释锁及进程池和线程池
    线程的互斥锁、递归锁及信号量
    守护、互斥锁、IPC和生产者消费者模型
    并发编程基础(进程)
    网络编程
  • 原文地址:https://www.cnblogs.com/ganler1988/p/1987378.html
Copyright © 2011-2022 走看看