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里面已经处理了 是根据年月来计算的

  • 相关阅读:
    Makoto and a Blackboard CodeForces
    Bash Plays with Functions CodeForces
    2016 计蒜之道 初赛 第一场 D 青云的机房组网方案 (虚树)
    常用数论函数求和公式
    AC日记——元素查找 codevs 1230
    AC日记——鬼谷子的钱袋 codevs 2998
    AC日记——接龙游戏 codevs 1051
    AC日记——逆波兰表达式 openjudge 3.3 1696
    AC日记——欧几里得的游戏 洛谷 P1290
    AC日记——刺激 codevs 1958
  • 原文地址:https://www.cnblogs.com/ganler1988/p/1987378.html
Copyright © 2011-2022 走看看