Boatstrap日历禁用不起作用

时间:2015-06-30 12:39:27

标签: javascript jquery datepicker

我无法从当前数据中禁用上一个日期。

检查我的代码 -

$(function() {
                window.prettyPrint && prettyPrint();
                //$('#dp1').datepicker({minDate: 0});


                /*$('#dp1').datepicker({startDate: '-0m'}).on('changeDate', function() {
                 $('#dp1').datepicker('hide');
                 });*/

                /*var date = new Date();
                 date.setDate(date.getDate() - 1);
                 $('#dp1').datepicker({startDate: date});*/


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

                $('#dp1').datepicker({
                    startDate: date
                });

            });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<script src="http://vanceblackburn.com/Demo/datepicker/js/bootstrap-datepicker.js"></script>


<link href="http://vanceblackburn.com/Demo/datepicker/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="http://vanceblackburn.com/Demo/datepicker/css/datepicker.css" />


<div class="form-group">
            <label class="control-label col-sm-4">Default Datepicker</label>
            <div class="col-sm-6">
                <input id="dp1" type="text" value="" size="16" class="form-control">
            </div>
        </div>

在我的日期选择器日历中,我想要禁用日历中的上一个日期。

如果今天是30-June-2015,则必须禁用所有上一个日期。仅显示日期,但不显示可点击的上一个日期。

相同的代码在这里Boatstrap Datepicker

1 个答案:

答案 0 :(得分:1)

我认为您应该使用todays日期初始化一个临时变量并将其设置为datepicker,就像这样

JS代码:

var nowDate = new Date();
var today = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0); //temporary variable with todays date

$('#dp1').datepicker({
  startDate: today,
  orientation: 'top' // will display the datepicker at bottom, as its 
                     //opposite to the orientation given, refer 
                     // https://github.com/eternicode/bootstrap-datepicker/issues/1035
});

HTML CODE:

    <div class="col-sm-6">
        <input id="dp1" type="text" value="" size="16" class="form-control" />
    </div>

现场演示@ JSFiddle:jsfiddle.net/dreamweiver/py7uotyf/3

注意:github上的Orientation(与实际值相反的关键字)已经出现了问题,https://github.com/eternicode/bootstrap-datepicker/issues/1035