JQuery UI Datapicker : How to add next/previous year buttons

给你一囗甜甜゛ 提交于 2019-12-22 04:06:13

问题


I use the feature of selecting a year with a dropdown. I use it to set birthdays of people at least 18 years old. So far it works perfectly. I have set it up using theseg parameters:

        $('#datepicker').datepicker({
        changeMonth: true,
        changeYear: true,
                    dateFormat: 'dd-mm-yy',
                    minDate: '-100Y',
                    maxDate: '-18Y'
    });

However I'd like to have year navigation. Is it possible to add a next/previous year button?

Thanks in advance for any help!


回答1:


Check this : http://jqueryui.com/demos/datepicker/dropdown-month-year.html its part of datepicker plug in

$(function() {
  $('#datepicker').datepicker({
   changeMonth: true,
   changeYear: true
  });
 });



回答2:


In order to complete the @PranayRana's answer, jQuery UI gives you the possibility to select the year with the option changeYear, and you are also able to specify the date range to your datepicker (for a birth date field for example).

Here's an example :

$(".datepicker").datepicker({
    changeYear: true, // Add the ability to select the year
    yearRange: '1930:2000', // Set the year range selection from 1930 to 2000
});


来源:https://stackoverflow.com/questions/3423670/jquery-ui-datapicker-how-to-add-next-previous-year-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!