<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Date_Month.ascx.cs" Inherits="Mvcb2b.admin.controls.Date_Month" %>
<div id="date_month" style="float:left;">
<select id="qi_year" name="qi_year">
<option value="">选择年份</option>
</select>
<select id="qi_month" name="qi_month">
<option value="">选择月份</option>
</select>
</div>
<script type="text/javascript">
    $(function () {
        // var ldate_month = document.getElementById("date_month");
        var yearurl = "jquery/Year.aspx";
        var monthurl = "jquery/Month.aspx";
        var selyear = document.getElementById("qi_year");
        var selmonth = document.getElementById("qi_month");
        //加载年份
        loadyear(selyear, "", yearurl);
        $("#qi_year").change(function(){//这里是正式变化;
            selmonth.options.length = 0;
            opt(selmonth, "选择月份", "", 0);
            var tempv = this.options[this.selectedIndex].value;
            if (tempv != "") {
                loadmonth(selmonth, tempv,"", monthurl);
            }
        });
    });

    function loadmonth(sel, nowyear,nowmonth, fileurl) {
        //加载月份
        $.ajax({
            type: "POST",
            url: fileurl, //
            dataType: "json",
            data: { "year": "" + nowyear + "" }, 
            success: function (json) {
                if (json != 0) {
                    var issel = 0;
                    for (i = 0; i < json.classtable.length; i++) { //json为回传的数据；"classtable"表名在回传的json数据
                        issel = 0
                        if (json.classtable[i].month == nowmonth) {
                            issel = 1;
                        }
                        opt(sel, json.classtable[i].month+"月", json.classtable[i].month, issel); //opt
                    }
                }

            }, error: function (json) { alert("error-$.ajax" + json); }
        });
    }

    function loadyear(sel,nowyear,fileurl) {
        //加载年份
        $.ajax({
            type: "POST",
            url: fileurl, //
            dataType: "json",
            success: function (json) {
                if (json != 0) {
                    var issel = 0;
                    for (i = 0; i < json.classtable.length; i++) { //json为回传的数据；"classtable"表名在回传的json数据
                        issel = 0
                        if (json.classtable[i].year == nowyear) {
                            issel = 1;
                        }
                        opt(sel, json.classtable[i].year, json.classtable[i].year, issel); //opt
                    }
                }

            }, error: function (json) { alert("error-$.ajax" + json); }
        });
    }
    function opt(sel,txt,value,issel){
        var op = document.createElement("option");
        op.value = value;
        op.text = txt;
        if (issel == 1)
            op.setAttribute("selected", "selected");
        sel.options.add(op);
    }
</script>
