如何在 Jquery ui 中禁用日期选择器(日历)中的过去日期?
how do i disable the past dates in a datepicker (calendar) in Jquery ui?
我正在开发一个预订系统,我需要使用 Jquery 禁用过去的日期。我已经下载了 JqueryUI 并尝试使用 beforeshowday 函数来禁用过去的日期。
如果您使用的是 de DatePicker,您可以按如下方式限制日期范围:
$( "#datepicker" ).datepicker({ minDate: -20, maxDate: "+1M +10D" });
-20
表示20天前,maxDate
表示1个月零10天后。
为了避免用户 select 在当前日期之前的任何日期使用:
$("#datepicker").datepicker({ minDate: 0 });
来源:
https://jqueryui.com/datepicker/#min-max
https://api.jqueryui.com/datepicker/#entry-examples
样本
$( "#datepicker" ).datepicker({ minDate: 0 });
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>datepicker demo</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<div id="datepicker"></div>
</body>
</html>
我正在开发一个预订系统,我需要使用 Jquery 禁用过去的日期。我已经下载了 JqueryUI 并尝试使用 beforeshowday 函数来禁用过去的日期。
如果您使用的是 de DatePicker,您可以按如下方式限制日期范围:
$( "#datepicker" ).datepicker({ minDate: -20, maxDate: "+1M +10D" });
-20
表示20天前,maxDate
表示1个月零10天后。
为了避免用户 select 在当前日期之前的任何日期使用:
$("#datepicker").datepicker({ minDate: 0 });
来源:
https://jqueryui.com/datepicker/#min-max
https://api.jqueryui.com/datepicker/#entry-examples
样本
$( "#datepicker" ).datepicker({ minDate: 0 });
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>datepicker demo</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<div id="datepicker"></div>
</body>
</html>