jQuery DatePicker 最小最大日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14646008/
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
jQuery DatePicker Min Max dates
提问by Rob
I have the jQuery date picker setup and working but would like help with setting the minDate and maxDate options. My current code is below (without these options). How can I set the minDate as 3 months before the defaultDate, and maxDate as 28days after the defaultDate?
我有 jQuery 日期选择器设置和工作,但想帮助设置 minDate 和 maxDate 选项。我当前的代码如下(没有这些选项)。如何将 minDate 设置为 defaultDate 之前的 3 个月,并将 maxDate 设置为 defaultDate 之后的 28 天?
var expdisp = $("#expdisp").attr("value");
$("#expirydate" ).datepicker({
showOn: "button",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
dateFormat: "dd/mm/yy",
defaultDate: expdisp,
showOtherMonths: true,
selectOtherMonths: true,
changeMonth: true,
changeYear: true,
});
回答by MuhammadHani
$(function() {
$( "#datepicker" ).datepicker({
changeYear: true,
minDate: '-3M',
maxDate: '+28D',
});
});
UPDATE
更新
You can calculate tour max and min valid dates from the default date, then assign it to the date picker.
您可以根据默认日期计算游览最大和最小有效日期,然后将其分配给日期选择器。
var expdisp = $("#expdisp").attr("value");
$("#expirydate" ).datepicker({
showOn: "button",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
dateFormat: "dd/mm/yy",
defaultDate: expdisp,
showOtherMonths: true,
selectOtherMonths: true,
changeMonth: true,
changeYear: true,
minDate: '-3M',
maxDate: '+28D',
});
回答by ramsurya
maxDate:- Sets the maximum date that can be selected. Accepts a date object or a relative number. For example: +7, or a string such as +6m.
maxDate:- 设置可以选择的最大日期。接受日期对象或相对数字。例如:+7,或 +6m 等字符串。
minDate :-Sets the minimum date that can be selected. Accepts a number, date object, or string.
minDate :-设置可以选择的最小日期。接受数字、日期对象或字符串。
$(document).ready(function() {
$("#date").datepicker({
minDate: -3,
maxDate: "1w"
});
});
});
回答by Jason
You can also use specific date ranges. I added a min beginning date with a +14D max. You just need to remember to stay consistent with your date format and use "/" instead of "-" between MM/DD/YYYY.
您还可以使用特定的日期范围。我添加了一个最小开始日期,最大值为 +14D。您只需要记住与您的日期格式保持一致,并在 MM/DD/YYYY 之间使用“/”而不是“-”。
$('#Date').datepicker({
changeMonth: true,
minDate: '10/19/2016',
maxDate: '+14D',
});
回答by Vinesh Winslet
$(document).ready(function () {
$('input[id$=tbDate]').datepicker({
dateFormat: 'dd-mm-yy',
minDate: '-0D',
maxDate: '+28D',
});
});
回答by SteveW
Your could try:
你可以试试:
var expdisp = $("#expdisp").attr("value");
$("#expirydate" ).datepicker({
showOn: "button",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
dateFormat: "dd/mm/yy",
defaultDate: expdisp,
showOtherMonths: true,
selectOtherMonths: true,
changeMonth: true,
changeYear: true,
minDate: -3M,
maxDate: +28D
});