2016-02-25 271 views
0

我想,當calender.html加載minRange和maxRange被自動選擇如何在默認日期範圍內給日期選擇器?

calender.html

<html> 
    <head> 
    <script src="http://code.jquery.com/jquery-1.12.0.min.js"></script> 
    <link href="datepicker.min.css" rel="stylesheet" type="text/css"> 
    <script src="datepicker.min.js"></script> 

    <!-- Include English language --> 
    <script src="datepicker.en.js"></script> 

    <script type="text/javascript"> 
    var date = new Date(); 
    var currentMonthStartDay = new Date(date.getUTCFullYear(), date.getUTCMonth(), 1); 
    var currentMonthLastDay = new Date(date.getUTCFullYear(), date.getUTCMonth() + 1, 0); 


     $('#my-element').data('datepicker').minRange = currentMonthStartDay; 
     $('#my-element').data('datepicker').maxRange = currentMonthLastDay; 


    </script> 
    </head> 
    <body> 
    <!-- <input type='text' class="datepicker-here" data-position="right top" /> --> 
    <div class="datepicker-here" id='my-element' data-language='en' data-range="false"></div> 
    </body> 
</html> 

我不能設置minRange和maxRange

回答

0

嘗試這樣

$('#minMaxExample').datepicker({ 
    language: 'en', 
    minDate: new Date() // Now can select only dates, which goes after today 
}) 
0

可以使用空氣日期選擇器的方法selectDate()這樣的:

var datepicker = $('#my-elem').datepicker().data('datepicker'); 
datepicker.selectDate(startDate); 
datepicker.selectDate(endDate); 

確保您的startDate和結束日期是一個JavaScript日期,如果不是,請使用

new Date(startDate) 
0

就我而言,我有限的日期選擇,使用戶只看到兩個日期之間的日期:今天和接下來的一天(分配10天后來=這是一個變量,你可以改變它,只要你想) assumed that today is 07/27/2017 thus 05/08/2017 would be 10days later~yay

第一: 我的代碼:

var myDate=new Date() ; 
// Variable Declare=today 
var spanDay = myDate.getDate(); 
myDate.setDate(spanDay + 10); 
//code above means you have assigned 10 days after myDate 

然後:

//in datepicker plugin 

var $cells = $('#custom-cells'); 
$cells.data('datepicker'); 
$cells.datepicker({ 
     todayButton: new Date(), 
     minDate: new Date(), 

     maxDate:myDate, 
     onRenderCell: function (date, cellType) { 
      if (cellType == 'day') { 
       var day = date.getDay(), 
        isDisabled = disabledDays.indexOf(day) != -1; 
       return { 
        disabled: isDisabled 
       } 
      } 
     } 
    });