在 Bootstrap 日期选择器中禁用过去的日期
Disable past dates in Bootstrap datepicker
我在 PHP 中有一个应用程序,我在其中使用 bootstrap 日期选择器。
我需要在日期选择器中禁用今天之前的所有过去日期。我因为这样做而被提到这个 link。
我根据该源中提供的信息编辑了日期选择器的 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>
谁能帮我做这个?
我通过这样做使它工作:
var date = new Date();
date.setDate(date.getDate());
$('.sandbox-container input').datepicker({
format: "dd/mm/yyyy",
orientation: "auto",
startDate: date,
clearBtn: true
});
试试这个。
$(".datepicker").datepicker({
showOn: 'button',
dateFormat: "yy-mm-dd",
changeMonth: true,
minDate: new Date,
changeYear: true,
autoclose: false
});
<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>
我在 PHP 中有一个应用程序,我在其中使用 bootstrap 日期选择器。
我需要在日期选择器中禁用今天之前的所有过去日期。我因为这样做而被提到这个 link。
我根据该源中提供的信息编辑了日期选择器的 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>
谁能帮我做这个?
我通过这样做使它工作:
var date = new Date();
date.setDate(date.getDate());
$('.sandbox-container input').datepicker({
format: "dd/mm/yyyy",
orientation: "auto",
startDate: date,
clearBtn: true
});
试试这个。
$(".datepicker").datepicker({
showOn: 'button',
dateFormat: "yy-mm-dd",
changeMonth: true,
minDate: new Date,
changeYear: true,
autoclose: false
});
<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>