如何在datepicker年份范围开始年终?

时间:2018-05-02 03:10:19

标签: javascript asp.net asp.net-mvc asp.net-mvc-3

如何修复ASP.NET MVC中datepicker Datetime的年份范围开始年份?

我的代码是

脚本:

<script type="text/javascript">

    $(document).ready(function () {
        $('input[type=datetime]').datepicker({
            dateFormat: "dd/mm/yy",
            changeMonth: true,
            changeYear: true,
            yearRange: "-60:+0"
        });

    });
</script>

查看

@Html.DropDownListFor(m => m.Gender, Model.GenderList, "- Select Gender -", new { @class = "form-control" })


@Html.EditorFor(m => m.Dateofbirth, new { @class = "form-control datepicker" }).

我的问题是如何确定dateofbirth字段中的年份范围datepicker取决于性别价值..

前:

Gender==Male dateofbirth year select Option starts from (currentYear - 21)
Gender==Female dateofbirth year select Option starts from (currentYear - 18)

在dateofbirth字段中选择性别值更改更改年份范围后,显示错误消息。

1 个答案:

答案 0 :(得分:0)

<强>解释

jQuery Datepicker有一个yearRange property allows user来设置startend year范围displayed Year Dropdown内的jQuery Datepicker

  

值的语法是'{Start-Year}:{End-Year}'

<script type = "text/javascript">
 $(function() {
$('.date-picker').datepicker( {
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    dateFormat: 'yy',
    onClose: function(dateText, inst) { 
        $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
    }
});
 $('.date-picker2').datepicker( {
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    dateFormat: 'yy',
    onClose: function(dateText, inst) { 
        $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
    }
});
  });
   </script>

在js小提琴中运行代码:

click here