jquery date range datepicker format
I am havin开发者_开发技巧g trouble figuring out how to set the format for the date range. I am new to jquery and I learned how to set the single datepicker, I am just having trouble with the date range. Here is the function
$(function() {
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
Here's my setup function for the datapicker - I found that it was hard work setting dates that were a long way from the current date but the control allows you to turn both the month and year into dropdowns so it's much easier to select a wide range of dates. You can set the forward and backward range of the year combo with the yearRange parameter.
$(document).ready(function () {
Date.format = 'dd/mm/yyyy';
$(".datepicker").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '-90:+5'
});
});
set { minDate: -20, maxDate: "+1M +10D" }
or use
$( ".selector" ).datepicker({ minDate: new Date(2007, 1 - 1, 1) });
$( ".selector" ).datepicker({ maxDate: '+1m +1w' });
Reference
精彩评论