我正在尝试在模态视图中实现bootstrap的日期时间选择器,如下面的截图:
我的代码如下:
HTML:
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="H3">Add New Overtime</h4>
</div>
<div class="modal-body">
<div class="form-group">
<div class='input-group date' id='ot_date'>
<input type='text' class="form-control datepicker" placeholder="Enter OT Date" />
<span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span>
</div>
</div>
<div class="form-group">
<div class='input-group date' id='ot_timein'>
<input type='text' class="form-control" placeholder="Enter OT Time-in"/>
<span class="input-group-addon"> <span class="glyphicon glyphicon-time"></span> </span>
</div>
</div>
<div class="form-group">
<div class='input-group date' id='ot_timeout'>
<input type='text' class="form-control" placeholder="Enter OT Time-out" />
<span class="input-group-addon"> <span class="glyphicon glyphicon-time"></span> </span>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>
<button type="submit" class="btn btn-primary">
Save
</button>
</div>
</div>
JS:
<script type="text/javascript">
$(document).ready(function() {
$('#ot_date').datetimepicker();
$('#ot_timein').datetimepicker({
language: 'en',
pick12HourFormat: true
});
$('#ot_timeout').datetimepicker({
language: 'en',
pick12HourFormat: true
});
});
我检查了以下链接,但仍然没有明确的答案。
Query1 - DateTime picker in bootstrap is not working
Query 2 - Twitter bootstrap datetime-picker not showing properly in modal
Query 3 - Bootstrap datetime-picker showing in modal as partial
答案 0 :(得分:0)
您想要为此元素初始化选择器:$('# ot_date ')。datetimepicker()。 但它是一个'div'元素,而不是输入。尝试将您的HTML更改为:
<div class="form-group">
<div class='input-group date'>
<input type='text' class="form-control datepicker" id="ot_date" placeholder="Enter OT Date" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
答案 1 :(得分:0)
首先,非常感谢 @Guruprasad Rao 让我知道我的代码中遗漏了什么。我在控制台中发现在调用bootstrap-datetimepicker.js之前首先需要Moment.js。所以你可以下载the Moment.js from here.
在我的代码中,我实现了如下:
<script src="<?php echo base_url(); ?>assets/bootstrap/plugins/datetimepicker/js/moment.js"></script>
<script src="<?php echo base_url(); ?>assets/bootstrap/plugins/datetimepicker/js/bootstrap-datetimepicker.js"></script>
提醒:必须在datetimepicker.js之前首先调用Moment.js
其次,非常感谢 @Melvas 。我向你们致敬。谢谢你纠正我的代码。如你所说,ID =&#34; ot_date&#34;在输入元素中添加NOT不在DIV中。好心......