Javascript Boatstrap日历禁用不工作
我无法从当前数据中禁用上一个日期 检查我的代码-Javascript Boatstrap日历禁用不工作,javascript,jquery,datepicker,Javascript,Jquery,Datepicker,我无法从当前数据中禁用上一个日期 检查我的代码- $(函数(){ window.prettyPrint&&prettyPrint(); //$('#dp1').datepicker({minDate:0}); /*$('#dp1').datepicker({startDate:'-0m'}).on('changeDate',function()){ $('#dp1')。日期选择器('hide'); });*/ /*变量日期=新日期(); date.setDate(date.getDate()-
$(函数(){
window.prettyPrint&&prettyPrint();
//$('#dp1').datepicker({minDate:0});
/*$('#dp1').datepicker({startDate:'-0m'}).on('changeDate',function()){
$('#dp1')。日期选择器('hide');
});*/
/*变量日期=新日期();
date.setDate(date.getDate()-1);
$('#dp1').datepicker({startDate:date})*/
变量日期=新日期();
date.setDate(date.getDate()-1);
$('#dp1')。日期选择器({
开始日期:日期
});
});代码>
默认日期选择器
我认为您应该使用todays
date初始化一个临时变量,并将其设置为日期选择器,如下所示
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
});
<div class="col-sm-6">
<input id="dp1" type="text" value="" size="16" class="form-control" />
</div>
HTML代码:
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
});
<div class="col-sm-6">
<input id="dp1" type="text" value="" size="16" class="form-control" />
</div>
现场演示@JSFiddle:JSFiddle.net/dreamweiver/py7uotyf/3
注意:在github上已经出现了一个关于方向(关键字与实际值相反)的问题。是的,您的代码工作正常。但当我在我的代码中放入相同的代码时,它就不起作用了(@chinu:这很奇怪,你能为日期选择器使用正确的id
吗?你能在我提供的jsfiddle上复制相同的吗?当我将bootstrap-datepicker.js
更改为bootstrap-datepicker.min.js
时,日历总是在文本框的顶部:(我需要它的绝对位置。如果我的文本框在底部,则日历显示在该文本框的顶部。如果文本框在顶部,则日历显示在文本框的下方。@chinu:这里有很多方向选项用于日期选择器
,您可以选择相同的。。像这样$('#dp2')。日期选择器({方向:'底部自动'});