Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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 日期选择器的最小最大月份_Jquery_Datepicker - Fatal编程技术网

Jquery 日期选择器的最小最大月份

Jquery 日期选择器的最小最大月份,jquery,datepicker,Jquery,Datepicker,我正在使用jquery ui datepicker设置两个月和一年的选取器我想限制第二个月和一年的选取器只在第一个日期选取器的月份和年份之后才被选择我不知道这是否可能请给我指导如果可能我的脚本如下 <script> $(document).ready( function () { $( "#date1_in_id" ).datepicker({ changeMonth: true,//this option for allowing user to

我正在使用jquery ui datepicker设置两个月和一年的选取器我想限制第二个月和一年的选取器只在第一个日期选取器的月份和年份之后才被选择我不知道这是否可能请给我指导如果可能我的脚本如下

<script>
$(document).ready(
    function () {
      $( "#date1_in_id" ).datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: "mm-yy",
        showButtonPanel: true,
        onClose: function(dateText, inst) { 
        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        $(this).datepicker('setDate', new Date(year, month, 1));
       }

      });
       $( "#date2_in_id" ).datepicker({
         changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: "mm-yy",           
        showButtonPanel: true,
        onClose: function(dateText, inst) { 
        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        $(this).datepicker('setDate', new Date(year, month, 1));
       }            
      });

    });

</script>
<style>.ui-datepicker-calendar{display: none;}</style>
您可以使用minDate和maxDate设置最小或最大日期


此处的更多信息:

当然可以使用此脚本,用户需要选择第一个日期选择器,然后可以在第一个日期选择器的日期之后选择第二个日期选择器

在\u id中的第一个$date1\u中替换此项的一次关闭:

     onClose: function( selectedDate ) {

        lafecha = selectedDate.split('-');
        fecha_alreves = lafecha[2]+'-'+lafecha[1]+'-'+lafecha[0];


        fecha = new Date(fecha_alreves);

        ayer = new Date(fecha);
        ayer.setTime(ayer.getTime() - 1000*60*60*24);
        dias = ayer.getDate();
        dias += 01;
        dia = ayer.getDay() + 1;
        mes = ayer.getMonth() + 1;
        anno = ayer.getFullYear() + 1;
        nuevafecha = mes+"-"+dias+"-"+anno;

        $( "#date2_in_id" ).datepicker( "option", "minDate", selectedDate );
        $( "#date2_in_id" ).datepicker( "option", "maxDate", nuevafecha );
    }
然后在\u id中替换这个$date2\u的onClose

    onClose: function( selectedDate ) {
        $( "#date1_in_id" ).datepicker( "option", "maxDate", selectedDate );
    }

我希望这对你有用

我想限制月份和年份这是日期限制我只想限制月份和年份我用的是01-2015