[英]Setting the minimum date of jquery datepicker
I am working on a project which involves using HTML5 and Javacript/JQuery. 我正在从事一个涉及使用HTML5和Javacript / JQuery的项目。 I am trying to make use of the Jquery datepicker and trying to set the minimum date to today's date so the user can't select a date from yesterday.
我试图利用Jquery datepicker并尝试将最小日期设置为今天的日期,以便用户无法从昨天选择日期。
Below is my Javascript. 以下是我的Javascript。
$(function()
{
var today = new Date();
$("#txtStartDate").datepicker(
{
changeMonth: true,
numberOfMonths: 1,
minDate: new Date(today.getYear(), today.getMonth() +1, today.getDay()),
onClose: function(selectedDate)
{
$("#txtStartDate").datepicker("option", "dateFormat", "dd-mm-yy", selectedDate);
}
});
});
It doesn't seem to be making any difference as I can still go back to days before yesterday. 好像没有什么变化,因为我仍然可以回到昨天。
Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。
I guess you did'nt read the documentation ? 我想您没有阅读文档 ?
minDate
minDate
Type : Date or Number or String
类型 :日期或数字或字符串
Default: null The minimum selectable date.
默认值:null最小可选日期。 When set to null, there is no minimum.
设置为null时,没有最小值。 Multiple types supported:
支持多种类型:
Date: A date object containing the minimum date.
日期:包含最小日期的日期对象。
Number: A number of days from today.
数量:从今天开始的天数。 <- set to 0, it's no days from today !
<-设置为0,从今天开始没有天!
So setting minDate to 0 should work, right ! 所以将minDate设置为0应该可以,对!
$(function () {
var today = new Date();
$("#txtStartDate").datepicker({
changeMonth: true,
numberOfMonths: 1,
minDate: 0,
onClose: function (selectedDate) {
$("#txtStartDate").datepicker("option", "dateFormat", "dd-mm-yy", selectedDate);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.