Create a specific date range with jQuery datepicker

前端 未结 2 1161
陌清茗
陌清茗 2021-02-06 09:54

I\'m trying to use the jQuery date picker to create a start date calendar and an end date calender. I\'m using the \"date range\" example seen here: http://jqueryui.com/demos/da

2条回答
  •  无人及你
    2021-02-06 10:39

    There you go : http://jsfiddle.net/c0mm0n/SJhmF/3/

    $(function() {
        $( "#from, #to" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 3,
            onSelect: function( selectedDate ) {
                if(this.id == 'from'){
                  var dateMin = $('#from').datepicker("getDate");
                  var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(),dateMin.getDate() + 1); // Min Date = Selected + 1d
                  var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(),dateMin.getDate() + 31); // Max Date = Selected + 31d
                  $('#to').datepicker("option","minDate",rMin);
                  $('#to').datepicker("option","maxDate",rMax);                    
                }
    
            }
        });
    });
    

提交回复
热议问题