Bootstrap datetimepicker is not a function

前端 未结 4 1974
余生分开走
余生分开走 2020-12-10 10:28

I am trying to use the datetimepicker from http://eonasdan.github.io/bootstrap-datetimepicker/ and I am getting the error \"Uncaught TypeError: $(...).datetimepicker is not

相关标签:
4条回答
  • 2020-12-10 10:50

    Below is the right code. Include JS files in following manner:

    $(document).ready(function() {
      $(function() {
        $('#datetimepicker6').datetimepicker();
        $('#datetimepicker7').datetimepicker({
          useCurrent: false //Important! See issue #1075
        });
        $("#datetimepicker6").on("dp.change", function(e) {
          $('#datetimepicker7').data("DateTimePicker").minDate(e.date);
        });
        $("#datetimepicker7").on("dp.change", function(e) {
          $('#datetimepicker6').data("DateTimePicker").maxDate(e.date);
        });
      });
    });
    <html>
    
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    
    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
    
    <body>
    
    
    
      <div class="container">
        <div class='col-md-5'>
          <div class="form-group">
            <div class='input-group date' id='datetimepicker6'>
              <input type='text' class="form-control" />
              <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
              </span>
            </div>
          </div>
        </div>
        <div class='col-md-5'>
          <div class="form-group">
            <div class='input-group date' id='datetimepicker7'>
              <input type='text' class="form-control" />
              <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
              </span>
            </div>
          </div>
        </div>
      </div>
    
    
    
    </body>
    
    
    </html>

    0 讨论(0)
  • 2020-12-10 10:54

    Try to use datepicker/ timepicker instead of datetimepicker like:

    replace:

    $('#datetimepicker1').datetimepicker();
    

    with:

    $('#datetimepicker1').datepicker(); // or timepicker for time picker
    
    0 讨论(0)
  • 2020-12-10 10:59

    I changed the import sequence without fixing the problem, until finally I installed moments and tempus dominius (Core and bootrap), using npm and include them in boostrap.js

    try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');
    require('moment'); /*added*/
    require('bootstrap');
    require('tempusdominus-bootstrap-4');/*added*/} catch (e) {}
    
    0 讨论(0)
  • 2020-12-10 11:09

    The problem is that you have not included bootstrap.min.css. Also, the sequence of imports could be causing issue. Please try rearranging your resources as following:

    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>                       
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
    

    DEMO

    0 讨论(0)
提交回复
热议问题