Bootstrap datepicker禁用特定日期

时间:2018-06-07 15:20:15

标签: javascript arrays datepicker bootstrap-4

我希望使用bootstrap

禁用特定日期
<script>
  $(document).ready(function(){
    var date_input=$('input[name="date"]'); 
    var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
    date_input.datepicker({
      format: 'yyyy-mm-dd',
      container: container,
      minDate:new Date(),
      disabledDates: ["2018-06-08","2018-06-10"],
      autoclose: true,
    })
  })
</script>

任何人都可以帮助我吗?非常感谢

1 个答案:

答案 0 :(得分:1)

您已通过无效密钥。其datesDisabled不是disabledDates

$(document).ready(function(){
    var date_input=$('input[name="date"]'); 
    var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
    date_input.datepicker({
      format: 'yyyy-mm-dd',
      container: container,
      minDate:new Date(),
      datesDisabled: ['2018-06-08','2018-06-10'],
      autoclose: true,
    })
  })
@import url('https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css');
@import url('https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker3.css');
.datepicker table tr td.disabled,
.datepicker table tr td.disabled:hover {
  color: #b90000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
<input name="date">