2016-07-28 92 views
1

集MINDATE我有1日期選取器的變2日期選取我需要設置選定的日期是2日期選擇器的MINDATE值。這是我對於在引導日期選擇器

<input type="text" size="30" class="date_picker_from form-control valid" id="start" value="" name="start" aria-invalid="false"> 

<input type="text" size="30" class="date_picker_to form-control valid" id="end" value="" name="end" aria-invalid="false"> 


$('.date_picker_from').datepicker({ 
    setDate: new Date(), 
    format: 'dd/mm/yyyy', 
    todayHighlight: true, 
    autoclose:true, 
    startDate: '-0m', 
    minDate:0, 

}); 

$('.date_picker_to').datepicker({ 
    //setDate: new Date(), 
    format: 'dd/mm/yyyy', 
    todayHighlight: true, 
    autoclose:true, 
    startDate: '+1d', 
    minDate:0, 

}); 

$("#start").change(function() { 


var secondDate = new Date($("#start").datepicker("getDate")); 

var date2 = new Date(secondDate.getTime()); 


date2.setDate(date2.getDate() + 1); 
    $("#end").datepicker("setDate", date2); 
    $("#end").datepicker("minDate", date2); 
    $('#end').datepicker("option", "minDate", date2); 


}); 

這裏COE是jsfiddle鏈接

回答

0

使用onSelect回調選項

$('.date_picker_hotel_from').datepicker({ 
 
    setDate: new Date(), 
 
    format: 'dd/mm/yyyy', 
 
    todayHighlight: true, 
 
    autoclose: true, 
 
    startDate: '-0m', 
 
    minDate: 0, 
 
    onSelect: function(text, dt) { 
 
    $('#end').datepicker('option', 'minDate', text); 
 
    } 
 
}); 
 

 
$('.date_picker_hotel_to').datepicker({ 
 
    //setDate: new Date(), 
 
    format: 'dd/mm/yyyy', 
 
    todayHighlight: true, 
 
    autoclose: true, 
 
    startDate: '+1d', 
 
    minDate: 0, 
 

 
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
 
<script src="//code.jquery.com/ui/1.8.18/jquery-ui.min.js"></script> 
 
<link href="http://code.jquery.com/ui/1.8.18/themes/base/jquery-ui.css" rel="stylesheet" /> 
 
<input type="text" size="30" class="date_picker_hotel_from form-control valid" id="start" value="" name="start" aria-invalid="false"> 
 

 
<input type="text" size="30" class="date_picker_hotel_to form-control valid" id="end" value="" name="end" aria-invalid="false">

1

這僅僅是你需要的一套做的事mindate.This是使用datepicker設置mindate的方法。

$("#start").change(function() {  
    $(".date_picker_hotel_to").datepicker("option", "minDate", $("#start").val()); 
});