Javascript Bootstrap datetimepicker 不适用于只读或禁用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/30298208/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap datetimepicker don't work with readonly or disabled
提问by Codinga
I have a serious problem with bootstrap datetimepicker, Here is the jsfiddle: 
我对 bootstrap 有一个严重的问题datetimepicker,这是jsfiddle:
<br/>
<!-- padding for jsfiddle -->
<div class="row">
    <div class="col-md-12">
         <h6>datetimepicker1</h6>
        <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-calendar glyphicon"></span></span>
            </div>
        </div>
    </div>
</div>
The problem is that when i open my website in mobile, mobile keyboard triggered when i focus the input field so what i need is that only the datepickershow without keyboard. So for that i use readonlyor disabled, but the problem is that when i use one of them the bootstrap datetimepickerdoesn't work.
http://jsfiddle.net/faissal_aboullait/kx0e5wmq/1/
问题是当我在移动设备上打开我的网站时,当我聚焦输入字段时会触发移动键盘,所以我需要的是只有datepicker没有键盘的节目。因此,我使用readonlyor disabled,但问题是当我使用其中之一时,引导程序datetimepicker不起作用。
http://jsfiddle.net/faissal_aboullait/kx0e5wmq/1/
回答by DavidDomain
If your are still looking for a solution take a look at the snippet. This is exactly what i suggested in the comment, you just have to call datetimepicker with
如果您仍在寻找解决方案,请查看代码段。这正是我在评论中建议的,你只需要调用 datetimepicker
ignoreReadonly: true
That's it.
就是这样。
$(function () {
  $('#datetimepicker').datetimepicker({
    ignoreReadonly: true
  });
});.container {
  margin-top: 80px;
}<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <div class='col-sm-6 col-sm-offset-3'>
        <div class="form-group">
          <div class='input-group date' id='datetimepicker'>
            <input type='text' class="form-control" readonly />
            <span class="input-group-addon">
              <span class="glyphicon glyphicon-calendar"></span>
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>Use the icon to pick your date not the text field. The text field is read only.
使用图标来选择您的日期而不是文本字段。文本字段是只读的。
回答by Webmaster G
This worked for me:
这对我有用:
.bootstrap-datetimepicker-widget.dropdown-menu  {
    width: 100%;
    max-width: calc(100%) !important;
}

