在Bootstrap datepicker中禁用过去的日期

时间:2018-05-06 07:17:55

标签: php bootstrap-datepicker

我在PHP中有一个应用程序,我使用bootstrap datepicker。

我需要在今天之前禁用datepicker中的所有过去日期。我这样做是为link提到的。

我根据该来源提供的信息编辑了datepicker的JS,但它仍然无效。

这是我的JS代码:

$('.sandbox-container input').datepicker({
  format: "dd/mm/yyyy",
  orientation: "auto",
  startDate: new Date(),          //here I tried to set the date
  clearBtn: true
});

这是我的PHP代码:

<div class="sandbox-container">
<div class="form-group col-sm-6 col-xs-12">
<input type="text" class="form-control date-selecter" value="Date From" id="datefrom" name="datefrom">
            </div>
<div class="form-group col-sm-6 col-xs-12">
<input type="text" class="form-control date-selecter" value="Date To" id="dateto" name="dateto">
                </div>
            </div>

有人可以帮我这样做吗?

2 个答案:

答案 0 :(得分:1)

我这样做了:

var date = new Date();
date.setDate(date.getDate());

$('.sandbox-container input').datepicker({
  format: "dd/mm/yyyy",
  orientation: "auto",
  startDate: date,
  clearBtn: true
});

答案 1 :(得分:0)

试试这个。

&#13;
&#13;
$(".datepicker").datepicker({
    showOn: 'button',
    dateFormat: "yy-mm-dd",
    changeMonth: true,
    
     minDate: new Date,
     
    changeYear: true,
    autoclose: false
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.13/jquery-ui.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="Stylesheet" type="text/css" />

<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" />
<input type="text" class="datepicker" /><br/>
<style>
    .ui-datepicker {font-size:60%; }
</style>
&#13;
&#13;
&#13;

相关问题