Jquery datepicker years change
I am using datepicker of jquery for a field to set date of birth, while default picker is displayed which gives option to scroll to date monthly and sounds tedious. Is there a way by which I can change years directly rather using months to change th开发者_如何学JAVAe year in turn.
There's a changeYear
property on the datepicker that you can set to true
.
$( ".selector" ).datepicker({ changeYear: true });
http://jqueryui.com/datepicker/#dropdown-month-year
This will render a select list from which you can choose the year you'd like.
Insert changeYear: true
on your DataPicker parameter.
Example :
$(function() {
$( ".datepicker" ).datepicker({
changeMonth: true,
changeYear: true
});
});
Set changeYear: true
, as shown in sample code below:
$("#birth_date").datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
maxDate: '-1D'
},
$.datepicker.regional["fr"]
);
Refer here for more options: https://jqueryui.com/datepicker/
changeYear
property lets you enable a year dropdown. Also might be helpful to use yearRange
property to control number of years they see in the dropdown, by default it's from -10 to +10 years.
$('#date').datepicker({
changeMonth: true,
changeYear: true,
yearRange: "-40:+40"
});
Details from original documentation:
The range of years displayed in the year drop-down: either relative to today's year ("-nn:+nn"), relative to the currently selected year ("c-nn:c+nn"), absolute ("nnnn:nnnn"), or combinations of these formats ("nnnn:-nn"). Note that this option only affects what appears in the drop-down, to restrict which dates may be selected use the minDate and/or maxDate options.
You can enable a year dropdown by using the 'changeYear' property (see: jQuery UI) from the datepicker object.
精彩评论