在datepicker中设置开始日期并限制日期

时间:2017-08-18 08:54:33

标签: javascript php jquery ajax laravel-5

我正在尝试将开始日期设置为从今天起的14天。 14天以下的日期将无法选择。我还需要锁定接下来的13天,因为无法选择。



$('#sandbox-container input').datepicker({
  format: 'mm/dd/yyyy',
  keyboardNavigation: false,
  forceParse: false,
  startDate: new Date(),
  autoclose: true
})

<input type="text" name="productDate" id="productDate" class="form-control" maxlength="20" placeholder="Date" value="{{ date('m/d/Y',strtotime($productDate))}}">
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

&#13;
&#13;
var newdate = new Date();
newdate.setDate(newdate.getDate() - 14);
$('input').datepicker({
  format: 'mm/dd/yyyy',
  keyboardNavigation: false,
  forceParse: false,
  minDate: newdate,
  startDate: newdate,
  autoclose: true
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.5.4/datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.5.4/datepicker.min.css" rel="stylesheet"/>
<input type="text" name="productDate" id="productDate" class="form-control" maxlength="20" placeholder="Date" value="">
&#13;
&#13;
&#13;