2017-03-17 57 views
1

嗨我需要禁用未來的日期,我試過所有的方式 但我無法讓我知道我錯了。如何使用angularjs和jquery禁用datepicker的未來日期

<div class="input-group date"> 
    <input type="text" class="form-control pull-right" id="datepicker2" placeholder="Date of Join" ng-model="DateofJoining"> 
    <div class="input-group-addon"></div> 
</div> 

$('#datepicker2').datepicker({ 
    autoclose: true, 
    maxDate: new Date() 
}); 

我甚至試過在angularjs也但無法禁用它們,請讓我知道如何禁用將來的日期。

我正在使用bootstrap-datepicker.js用於創建日期選擇器。

回答

0

似乎是它的正常工作在這個demo

確保相關的庫添加到HTML作爲腳本

<link rel="stylesheet"ref="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" /> 
<script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script> 
0

我的首要建議是使用由@krix

建議角指令

反正你可以根據你的代碼輸入禁用將來的日期如下

$(document).ready(function() { 
 
    $('.datepicker').datepicker({ 
 
     format: 'mm-dd-yyyy', 
 
     endDate: '+0d', 
 
    }); 
 
});
<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.js"></script> 
 
<link rel="stylesheet" type="text/css" href="http://www.eyecon.ro/bootstrap-datepicker/css/datepicker.css"> 
 
<link rel="stylesheet" type="text/css" href="http://getbootstrap.com/dist/css/bootstrap.min.css"> 
 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script> 
 

 
<input class="datepicker" />

相關問題