在bootstrap datetimepicker中插入标签

时间:2017-05-30 18:30:52

标签: javascript css bootstrap-datetimepicker eonasdan-datetimepicker

有没有办法在eonasdan的bootstrap datetimepicker中添加小时/分钟标签,如屏幕截图所示?

enter image description here

1 个答案:

答案 0 :(得分:0)

正如ceejayoz在评论中所述,datetimepicker不包含此类功能。该库是开源的,您可以自定义代码和外观。感觉如建议的那样。

另一个方法是在显示选择器时在小时和分钟行下添加一行。您可以向dp.show事件添加一个列表器,然后使用jQuery来操作选择器HTML。

这是一份工作样本:



$('#datetimepicker1').datetimepicker({
  format: 'HH:mm'
});

$('#datetimepicker1').on('dp.show', function(){
  // Check timepicker is visible
  if( $('.timepicker').is(':visible') ){
    // Get rows of the timepicker
    var rows = $('.timepicker>.timepicker-picker>table>tbody>tr');
    // Create html for custom text
    var tr = '<tr class="customText"><td>hours</td><td class="separator"></td><td>minutes</td></tr>';
    // Add custom HTML inside component
    $(rows[1]).after(tr);
  }
});
&#13;
.bootstrap-datetimepicker-widget table tr.customText td {
  height: 24px;
  line-height: 24px;
}
&#13;
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>


<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>
&#13;
&#13;
&#13;

datetimepicker具有debug选项,如果设置为true

  

将导致日期选择器在blur事件后保持打开状态。