bootstrap-datepicker错误:datepicker不是函数

有人可以帮我解决这个错误吗?在检查其他解决方案时,他们说他们两次声明了jquery,这就是它显示的原因。但就我而言,我只声明了一次jQuery。 请参见下面的代码片段:

$(document).ready(() => {
    $("#datepicker").datepicker({
        format: "mm-yyyy",
        startView: "months",
        minViewMode: "months"
    });
})
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>My Teasting Website</title>

  <!--Bootstrap css-->
  <link rel="stylesheet" href="src/bootstrap/css/bootstrap.min.css">
  <!--bootstrap-datepicker css-->
  <link rel="stylesheet" href="src/bootstrap-datePicker/css/bootstrap-datetimepicker.min.css">
</head>

<body>


    <input type="text" readonly="readonly" name="date" id = "datepicker">
    <span class="add-on"><i class="icon-th"></i></span>

  <!--Jquery js-->
  <script src="src/jquery.js"></script>
  <!--Bootstrap js-->
  <script src = "src/bootstrap/js/bootstrap.min.js"></script>
  <!--bootstrap-datepicker js -->
  <script src="src/bootstrap-datePicker/js/bootstrap-datetimepicker.min.js"></script>
  <script src = "js/script.js"></script>

</body>

</html>

下面是您的文件夹目录:

enter image description here

评论
  • 深夜、徘徊
    深夜、徘徊 回复

    Try to follow this example here...

    The difference in your code is that you used id instead of class in jquery:

    $(document).ready(() => {
      $(".datepicker").datepicker({
        format: "mm-yyyy",
        startView: "months",
        minViewMode: "months"
      });
    })
    

    另外,更改HTML:

    <div class="input-group date" data-provide="datepicker">
      <input type="text" class="form-control">
      <div class="input-group-addon">
        <span class="glyphicon glyphicon-th"></span>
      </div>
    </div>