我也使用 Stefan Petre 的 http://www.eyecon.ro/bootstrap-datepicker,如果不进行修改,它不适用于 Bootstrap 3。请注意,http://eternicode.github.io/bootstrap-datepicker/ 是 Stefan Petre 代码的一个分支。
您必须更改标记(示例标记不起作用)才能在 Bootstrap 3 中使用新的 CSS 和表单网格布局。此外,您必须在实际的 bootstrap-datepicker 实现中修改一些 CSS 和 JavaScript。
这是我的解决方案:
<div class="form-group row">
<div class="col-xs-8">
<label class="control-label">My Label</label>
<div class="input-group date" id="dp3" data-date="12-02-2012" data-date-format="mm-dd-yyyy">
<input class="form-control" type="text" readonly="" value="12-02-2012">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
</div>
datepicker.css 第 176-177 行的 CSS 更改:
.input-group.date .input-group-addon i,
.input-group.date .input-group-addon i {
第 34 行 datepicker-bootstrap.js 中的 Javascript 更改:
this.component = this.element.is('.date') ? this.element.find('.input-group-addon') : false;
更新
使用来自http://eternicode.github.io/bootstrap-datepicker/ 的新代码,更改如下:
datepicker.css 第 446-447 行的 CSS 更改:
.input-group.date .input-group-addon i,
.input-group.date .input-group-addon i {
第 46 行 datepicker-bootstrap.js 中的 Javascript 更改:
this.component = this.element.is('.date') ? this.element.find('.input-group-addon, .btn') : false;
最后,启用日期选择器的 JavaScript(带有一些选项):
$(".input-group.date").datepicker({ autoclose: true, todayHighlight: true });
使用 Bootstrap 3.0 和 JQuery 1.9.1 测试。请注意,这个叉子比其他叉子更好用,因为它功能更丰富,支持本地化并根据控件位置和窗口大小自动定位日期选择器,避免选择器离开屏幕,这是旧版本的问题版本。