如何修复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字段中选择性别值更改更改年份范围后,显示错误消息。
答案 0 :(得分:0)
<强>解释强>
jQuery
Datepicker
有一个yearRange property
allows user
来设置start
和end 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小提琴中运行代码: