【问题标题】:Linking Jquery-UI datepicker to DropDownlist将 Jquery-UI 日期选择器链接到 DropDownlist
【发布时间】:2015-03-03 16:24:02
【问题描述】:

是否有人将 Jquery ui 日期选择器链接到 3 个单独的下拉/选择列表(日月年),以便更改日期选择器或下拉列表中的月/年将限制天数下拉列表中可用的天数。

目前我只有一个选择列表,其中的值硬编码为 31,这允许一些无效日期。

我正在使用 c# 和 mvc。

谢谢

【问题讨论】:

    标签: javascript c# jquery jquery-ui model-view-controller


    【解决方案1】:

    为此,使用 Jquery UI Datepicker 已经过时了。简单地使用 javascript 日期将在这里为您提供帮助。

    这将向您展示如何获取相应月份的天数。 Get number days in a specified month using javascript?

    所以按月更改设置天数

    function daysInMonth(month,year) {
        return new Date(year, month, 0).getDate();
    }
    
    $('#month').change(function(){
        //fill dropdown with options correspinding
        //with the number of days returned from the daysInMonth function
    })
    

    【讨论】:

      【解决方案2】:

      我是如何解决的,如果有人在寻找类似的

      function disableDaysNotInMonth(daysInMonth) {
          $("#ddlDay option").each(function () {
                  if (this.text > daysInMonth) {
                      $(this).attr("disabled", true);
                  }
                  else {
                      $(this).attr("disabled", false);
                  }
          });
      };
      
      function ddlUpdate() {
          var ddlMonth = $("#ddlMonth").find(":selected").text();
          var ddlYear = $("#ddlYear").find(":selected").text();
          var daysInMonth = getDaysInMonth(ddlMonth, ddlYear);
          disableDaysNotInMonth(daysInMonth);
      };
      

      【讨论】:

        猜你喜欢
        • 2011-03-09
        • 1970-01-01
        • 2013-01-21
        • 2011-01-13
        • 2018-01-21
        • 1970-01-01
        相关资源
        最近更新 更多