Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 选择过去50年内的日期_Jquery_Datepicker - Fatal编程技术网

Jquery 选择过去50年内的日期

Jquery 选择过去50年内的日期,jquery,datepicker,Jquery,Datepicker,我试图通过jQuery datepicker选择一个过去50年的日期,但是select type of year只显示有限的年数。我不得不反复选择年份,回到过去的岁月 下面是我使用的jQuery脚本: $(".datepicker").datepicker({ changeMonth: true, changeYear: true, minDate: "-50Y", maxDate: "-6Y" }); 我制作了一把小提琴 请查收。我希望一次显示全年,而不是重复

我试图通过
jQuery datepicker
选择一个过去50年的日期,但是
select type of year
只显示有限的年数。我不得不反复选择年份,回到过去的岁月

下面是我使用的
jQuery
脚本:

$(".datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    minDate: "-50Y",
    maxDate: "-6Y"
});
我制作了一把小提琴
请查收。我希望一次显示全年,而不是重复选择它们。

另外,我想将日期显示为
yyyy-mm-dd
格式。

您可以使用yearRange

$(".datepicker").datepicker({
    dateFormat: 'yy-mm-dd',
    changeMonth: true,
    changeYear: true,
    yearRange: "-50:-6"
});

yearRange:“c-50:c-6”
添加到您的实例化中,如下所示

$(".datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    minDate: "-50Y",
    maxDate: "-6Y",
    yearRange: "c-50:c-6"
});
试着用

dateFormat: 'yy-mm-dd',


根据您的要求使用年份范围

  function loadDatePicker() {
        $('.datePicker').datepicker({
            dateFormat: 'yy-mm-dd',
            changeYear: true,
            changeMonth: true,
            yearRange: "-18:-12",
            defaultDate:"-18y-m-d"  // Relative year/month/day
        });
    }

非常感谢。这是我想要的,但如果你看到的话,会有一个小问题。从范围中选择一年,然后再次选择年份,上一年的详细信息将丢失。同样,我必须重新选择要追溯的年份或年份,而不是
defaultDate:“-18y-m-d”
仅使用
defaultDate:“-18y”
  function loadDatePicker() {
        $('.datePicker').datepicker({
            dateFormat: 'yy-mm-dd',
            changeYear: true,
            changeMonth: true,
            yearRange: "-18:-12",
            defaultDate:"-18y-m-d"  // Relative year/month/day
        });
    }