为什么我的datetimepicker不起作用

时间:2016-12-15 00:26:48

标签: twitter-bootstrap datetimepicker eonasdan-datetimepicker

我的datetimepicker不起作用,我不知道为什么,我只是从bootstrap中复制了这段代码。

以下是代码:

<div class="form-group">
    <label class="control-label col-sm-3" for="email">Birthdate:</label>
    <div class="col-sm-3">
        <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>

JavaScript的:

$(function () {
    $('#datetimepicker1').datetimepicker();
});

CSS:

<link rel="stylesheet" href="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/build/css/bootstrap-datetimepicker.css">

和JavaScript导入:

<script src="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/src/js/bootstrap-datetimepicker.js"></script>

1 个答案:

答案 0 :(得分:1)

此插件依赖于您似乎没有使用的Moment.js。请参阅Docs

最低要求

  1. 的jQuery
  2. Moment.js
  3. Bootstrap.js(如果您不是,则需要转换和折叠 使用完整的Bootstrap)
  4. Bootstrap Datepicker脚本
  5. Bootstrap CSS
  6. Bootstrap Datepicker CSS
  7. 区域设置:Moment的区域设置文件为here
  8. 工作示例:

    &#13;
    &#13;
    $(document).ready(function() {
      $(function() {
        $('#datetimepicker1').datetimepicker();
      });
    });
    &#13;
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
    <div class="container">
      <div class="row">
        <div class='col-sm-6 col-sm-offset-3'>
          <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>
    <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.17.1/moment.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/js/bootstrap-datetimepicker.min.js"></script>
    &#13;
    &#13;
    &#13;