如何在 jquery UI datepicker 中禁用今天之前的日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11115981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:13:06 来源:igfitidea点击:
How to disable dates before today in jquery UI datepicker?
提问by any user
I am making a hotel reservation system i have to disable past dates in jQuery UI datepicker here's the code
我正在制作一个酒店预订系统,我必须在 jQuery UI datepicker 中禁用过去的日期,这是代码
calling in .cs
调用 .cs
public class CheckLookup
{
[DataType(DataType.Date)]
public DateTime checkindate { get; set; }
[DataType(DataType.Date)]
public DateTime checkoutdate { get; set; }
}
Here's the javascript
这是javascript
$(document).ready(function () {
function getDateYymmdd(value) {
if (value == null)
return null;
return $.datepicker.parseDate("yy-mm-dd", value);
}
$('.date').each(function () {
var minDdate = getDateYymmdd($(this).data(""));
var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
$(this).datepicker({
dateFormat: "dd-mm-yy",
minDate: minDate,
maxDate: maxDate
});
});
});
tell me the modification to be done in this code.
告诉我要在此代码中进行的修改。
回答by thecodeparadox
You can try this:
你可以试试这个:
$('.date').datepicker({ minDate: 0 });
for you case:
对于你的情况:
$('.date').each(function () {
var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
$(this).datepicker({
dateFormat: "dd-mm-yy",
minDate: 0,
maxDate: maxDate
});
});