2016-12-29 239 views
0

我正在使用Materialise的自定義Pickadate datepicker。如何限制第二日期選擇器不超過第一日期選擇器的選定日期?

這是我的HTML,我使用Materialise的CSS

<div class="col s12 m6"> 
    <input type="date" id="check_in" class="datepicker1"> 
    <label for="Check-in">Check in date</label> 
</div> 
<div class="col s12 m6"> 
    <input type="date" id="check_out" class="datepicker2"> 
    <label for="check_out">Check out date</label> 
</div> 

這裏是我的javascript。

<script type="text/javascript"> 
    $('.datepicker1').pickadate({ 
    selectMonths: true, // Creates a dropdown to control month 
    selectYears: 1, // Creates a dropdown of 15 years to control year 
    min: true, 
    format: 'yyyy, mmmm d' 
    }); 

    $('.datepicker2').pickadate({ 
    selectMonths: true, // Creates a dropdown to control month 
    selectYears: 1, // Creates a dropdown of 15 years to control year 
    min: true, 
    format: 'yyyy, mmmm d' 
    }); 
    </script> 
+0

Materialise公司的日期選擇器是一種改性pickadate.js。如果你檢查插件的文檔,有'min'和'max'選項:http://amsul.ca/pickadate.js/date/#limits你需要編碼一下,以便每次重新初始化第二個datepicker第一次更改爲「min」選項。 – yuriy636

回答

2

當第一個日期選擇器更改時,您將運行以下代碼。 picker將是您的第一個約會者,picker2將是您的第二個約會者。 Onchange,抓住第一個選擇器的日期,並將其作爲第二個選擇器的最小值。

var date = picker.get() 
picker2.set('min', date) 

http://amsul.ca/pickadate.js/api/

相關問題