日历未显示在 Bootstrap datetimepicker 中
Calendar not showing up in Bootstrap datetimepicker
我正在使用以下代码实现 bootstrap datetimepicker:
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<div class="input-group date" id="datetimepicker1">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
我已经包含了以下脚本和样式:
我的输出如下所示:
包含文件的顺序是:
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/Styles/PreLayout.css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/moment")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/Scripts/JavaScripts/PreLayout.js")
当我点击日历图标时没有任何反应。我在实施中犯了什么错误?
编辑:
问题的原因是您没有按正确的顺序放置参考脚本。
查看文档:http://eonasdan.github.io/bootstrap-datetimepicker/Installing/
$('#datetimepicker1').datetimepicker();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="http://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/src/js/bootstrap-datetimepicker.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
您可能还想检查一下您使用的是什么图标集。
有多种字体图标集,如Font Awesome
、Material Design
、Bootstrap glyphicons
等
默认情况下 DateTimePicker
使用 Bootstrap glyphicons
,但您可以为所有其他内容指定自定义图标。
icons:{
time: 'glyphicon glyphicon-time',
date: 'glyphicon glyphicon-calendar',
up: 'glyphicon glyphicon-chevron-up',
down: 'glyphicon glyphicon-chevron-down',
previous: 'glyphicon glyphicon-chevron-left',
next: 'glyphicon glyphicon-chevron-right',
today: 'glyphicon glyphicon-screenshot',
clear: 'glyphicon glyphicon-trash',
close: 'glyphicon glyphicon-remove'
}
参考- http://eonasdan.github.io/bootstrap-datetimepicker/Options/#icons
至于文本框和日历图标之间乱七八糟的间距,我可以通过注释掉以下行来解决这个问题:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
我的项目会代我处理这个问题。 ASP.net/MVC
我还将 col-sm-6 更改为 col-sm-12。
类似的问题,但不同的解决方案
它特定于 ASP.NET 核心项目。在默认 visual studio 模板中,
所有输入标签的最大宽度都设置为 280px,如下所示:
文件: site.css
/* Set widths on the form inputs since otherwise they're 100% wide */
input,
select,
textarea {
max-width: 280px;
}
只需删除它,日历图标就会放在正确的位置:)
我在使用 jQuery 3.x 时遇到问题。 (最新版本 Bootstrap 3 支持 jQuery 3)。下拉菜单将部分呈现但没有日历。时间选择器部分工作正常。
降级到 jQuery 2.x 解决了问题。
我正在使用以下代码实现 bootstrap datetimepicker:
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<div class="input-group date" id="datetimepicker1">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
我已经包含了以下脚本和样式:
我的输出如下所示:
包含文件的顺序是:
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/Styles/PreLayout.css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/moment")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/Scripts/JavaScripts/PreLayout.js")
当我点击日历图标时没有任何反应。我在实施中犯了什么错误?
编辑:
问题的原因是您没有按正确的顺序放置参考脚本。
查看文档:http://eonasdan.github.io/bootstrap-datetimepicker/Installing/
$('#datetimepicker1').datetimepicker();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="http://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/src/js/bootstrap-datetimepicker.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
您可能还想检查一下您使用的是什么图标集。
有多种字体图标集,如Font Awesome
、Material Design
、Bootstrap glyphicons
等
默认情况下 DateTimePicker
使用 Bootstrap glyphicons
,但您可以为所有其他内容指定自定义图标。
icons:{
time: 'glyphicon glyphicon-time',
date: 'glyphicon glyphicon-calendar',
up: 'glyphicon glyphicon-chevron-up',
down: 'glyphicon glyphicon-chevron-down',
previous: 'glyphicon glyphicon-chevron-left',
next: 'glyphicon glyphicon-chevron-right',
today: 'glyphicon glyphicon-screenshot',
clear: 'glyphicon glyphicon-trash',
close: 'glyphicon glyphicon-remove'
}
参考- http://eonasdan.github.io/bootstrap-datetimepicker/Options/#icons
至于文本框和日历图标之间乱七八糟的间距,我可以通过注释掉以下行来解决这个问题:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
我的项目会代我处理这个问题。 ASP.net/MVC 我还将 col-sm-6 更改为 col-sm-12。
类似的问题,但不同的解决方案
它特定于 ASP.NET 核心项目。在默认 visual studio 模板中, 所有输入标签的最大宽度都设置为 280px,如下所示:
文件: site.css
/* Set widths on the form inputs since otherwise they're 100% wide */
input,
select,
textarea {
max-width: 280px;
}
只需删除它,日历图标就会放在正确的位置:)
我在使用 jQuery 3.x 时遇到问题。 (最新版本 Bootstrap 3 支持 jQuery 3)。下拉菜单将部分呈现但没有日历。时间选择器部分工作正常。
降级到 jQuery 2.x 解决了问题。