绑定下拉与jquery

时间:2014-05-27 11:21:31

标签: jquery asp.net

我正在约束一下#on;" onChange"文本框的事件。 它工作正常,但当我点击按钮时,它不会触发其点击事件

这是我的剧本

<script type="text/javascript">
    function FillMonthYear() {
        var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

        var StartDate = $('[Id$="lblStartDate"]').text();
        var EndDate = $('[Id$="txtEndDate"]').val();

        var StartYear = new Date(StartDate.split('/')[1] + "/" + StartDate.split('/')[0] + "/" + StartDate.split('/')[2]).getFullYear();
        var EndYear = new Date(EndDate.split('/')[1] + "/" + EndDate.split('/')[0] + "/" + EndDate.split('/')[2]).getFullYear();

        $("[Id$='ddlMonthYear']").empty();

        if (StartYear == EndYear) {
            for (var i = StartDate.split('/')[1]; i <= EndDate.split('/')[1]; i++) {
                //alert(months[i - 1] + " " + StartYear);
                $("[Id$='ddlMonthYear']").append("<option value='" + i + ":" + StartYear + "'>" + months[i - 1] + "-" + StartYear + "</option>");
            }
        }
        else if (StartYear > EndYear) {
            alert("not allowed");
        }
        else if (StartYear < EndYear) {
            for (var i = StartDate.split('/')[1]; i <= 12; i++) {
                //alert(months[i - 1] + " " + StartYear);
                $("[Id$='ddlMonthYear']").append("<option value='" + i + ":" + StartYear + "'>" + months[i - 1] + "-" + StartYear + "</option>");
            }
            for (var i = 1; i <= EndDate.split('/')[1]; i++) {
                //alert(months[i - 1] + " " + EndYear);
                $("[Id$='ddlMonthYear']").append("<option value='" + i + ":" + StartYear + "'>" + months[i - 1] + "-" + StartYear + "</option>");
            }
        }
    }

这是我的按钮

  <asp:ImageButton ID="ibtnAdd" runat="server" ToolTip="Add Production and Power Consumption"
                                            ImageUrl="~/admin/images/btn_add.png" ValidationGroup="Production" AlternateText="Add"
                                            OnClick="ibtnAdd_Click" />

这是我的文本框

 <asp:TextBox ID="txtEndDate" runat="server" ToolTip="Enter  Production Value" MaxLength="50"
                                            Width="150" CssClass="body_text capital" onchange="FillMonthYear()">
                                        </asp:TextBox>

1 个答案:

答案 0 :(得分:0)

使用文本框的onkeyup或onkeydown事件。