【发布时间】:2015-03-03 16:24:02
【问题描述】:
是否有人将 Jquery ui 日期选择器链接到 3 个单独的下拉/选择列表(日月年),以便更改日期选择器或下拉列表中的月/年将限制天数下拉列表中可用的天数。
目前我只有一个选择列表,其中的值硬编码为 31,这允许一些无效日期。
我正在使用 c# 和 mvc。
谢谢
【问题讨论】:
标签: javascript c# jquery jquery-ui model-view-controller
是否有人将 Jquery ui 日期选择器链接到 3 个单独的下拉/选择列表(日月年),以便更改日期选择器或下拉列表中的月/年将限制天数下拉列表中可用的天数。
目前我只有一个选择列表,其中的值硬编码为 31,这允许一些无效日期。
我正在使用 c# 和 mvc。
谢谢
【问题讨论】:
标签: javascript c# jquery jquery-ui model-view-controller
为此,使用 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
})
【讨论】:
我是如何解决的,如果有人在寻找类似的
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);
};
【讨论】: