正在将Jquery UI日期选择器链接到DropDownlist
本文关键字:选择器 链接 DropDownlist 日期 UI Jquery | 更新日期: 2024-09-25 12:17:40
是否有人将Jquery ui日期选择器链接到3个单独的下拉列表/选择列表(天-月-年),以便在日期选择器或下拉列表中更改月份/年将限制日期下拉列表中可用的天数。
目前,我只有一个选择列表,其中的值硬编码为31,这允许一些无效的日期。
我使用的是c#和mvc。
感谢
使用Jquery UI Datepicker在这方面做得太过火了。简单使用javascript日期将在这里对您有所帮助。
这将向您展示如何获取相应月份的天数。使用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);
};