2017-08-29 78 views
0

我正在使用jQuery UI DatePicker。我想從當前日期起2天后禁用日期。我怎樣才能做到這一點?禁用日期從Datepicker中的當前日期開始的2天以內

$(function() { 
 
    $("#datepicker").datepicker(); 
 
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
 
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 

 
<div class="form-group"> 
 
    <input type="text" id="datepicker" class="form-control" /> 
 
</div>

+0

這是在文檔中充分說明了一件微不足道的小事......你不讀呢? – CBroe

回答

2

要做到這一點,你可以使用maxDate屬性。提供+2將從當前價值2天。試試這個:

$(function() { 
 
    $("#datepicker").datepicker({ 
 
    maxDate: '+2' 
 
    }); 
 
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
 
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 

 
<div class="form-group"> 
 
    <input type="text" id="datepicker" class="form-control" /> 
 
</div>

1

您可以使用此代碼:

$(function() { 
    $("#datepicker").datepicker({ 
    maxDate: '+2' 
    }); 
}); 
相關問題