簡體   English   中英

BootStrap:未捕獲的TypeError:$(...)。datetimepicker不是函數

[英]BootStrap : Uncaught TypeError: $(…).datetimepicker is not a function

我剛剛開始使用BootStrap,但是Uncaught TypeError: $(...).datetimepicker is not a functionUncaught TypeError: $(...).datetimepicker is not a function錯誤消息。 有人能告訴我這段代碼遺漏了什么嗎?

從那以后,提到了多個類似的問題但無濟於事。

home_page.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Health Insurance</title>

<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.css">
<link rel="stylesheet" href="js/bootstrap-datepicker.min.css">
<link rel="stylesheet" href="css/bootstrap.css">

</head>

<body>
  <form role="form">

  <div class="form-group form-group-sm">
        <label class="col-sm-2 control-label" for="insuredName">Insured Name :</label>
            <div class="col-sm-3">
                <input class="form-control" type="text" id="insuredName" placeholder="Insured Name">
        </div>
    </div>


    <div class="form-group form-group-sm">
        <label class="col-sm-2 control-label" for="rel_PolicyHolder">Relation with Policy Holder :</label>
        <div class="col-sm-3">
            <input class="form-control" type="text" id="rel_PolicyHolder" placeholder="Relation with Policy Holder"> <br />
            <br />
        </div>
    </div>


<div class="container" >
<div class="col-sm-4" style="height:130px; align:right">

            <div class='input-group date'>
                <input type='text' class="form-control" id='datetimepicker9' /> 
                    <span class="input-group-addon"> 
                            <span class="glyphicon glyphicon-calendar"></span>
                    </span>

            <script src="js/jquery-1.11.2.min.js"></script></script>
            <script src="js/bootstrap.min.js"></script>
            <script src="js/bootstrap-datepicker.min.js"></script>


    <script type="text/javascript">
            $(function () {
            $('#datetimepicker9').datetimepicker({
            viewMode: 'years'
            });
        });
      </script>
     </div>

     </div>
    </div>

 </form>

 </body>
</html>

所有文件都放在Eclipse中的WebContent文件夾下,但outside META-INFWEB-INF文件夾之外。

css 文件夾 下的 文件

  • 自舉theme.css
  • bootstrap-theme.css.map
  • 自舉theme.min.css
  • bootstrap.css
  • bootstrap.css.map
  • bootstrap.min.css
  • enhanced.css
  • jQuery的ui.css
  • ui.daterangepicker.css

fonts 下的 文件

  • glyphicons,半身人,regular.eot
  • glyphicons,半身人,regular.svg
  • glyphicons,半身人,regular.ttf
  • glyphicons,半身人,regular.woff
  • glyphicons,半身人,regular.woff2

js 文件夾 下的 文件

  • 自舉datepicker.min.css
  • 引導-datepicker.min.js
  • bootstrap.js
  • bootstrap.min.js
  • date.js
  • enhance.min.js
  • fileinput.jquery.js
  • jQuery的1.11.2.min.js
  • jQuery的1.8.3.min.js
  • jQuery的1.9.0.min.js
  • jQuery的ui.js
  • npm.js

錯誤信息

Uncaught TypeError: $(...).datetimepicker is not a function

(anonymous function) @ home_page.html:82

m.Callbacks.j @ jquery-1.11.2.min.js:2

m.Callbacks.k.fireWith @ jquery-1.11.2.min.js:2

m.extend.ready @ jquery-1.11.2.min.js:2

J @ jquery-1.11.2.min.js:2

任何指導都值得注意

您正在使用datetimepicker當它應該是datepicker 按照文檔 試試這個它應該工作。

<script type="text/javascript">
  $(function () {
    $('#datetimepicker9').datepicker({
      viewMode: 'years'
    });
  });
 </script>

我有同樣的問題,你必須首先加載Moment.js文件!

 <script src="path/moment.js"></script> <script src="path/bootstrap-datetimepicker.js"></script> 

這有點晚了但我知道它會幫助某人:

如果您使用datetimepicker確保包含正確的CSS和JS文件。 datetimepicker使用(記下他們的名字);

https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css

https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js

關於@ mindfreak提出的上述問題,主要問題是由於導入的文件。

你們復制了錯誤的代碼。

如果你想要縮小版本,進入“/ build”文件夾並獲取jquery.datetimepicker.full.js或jquery.datetimepicker.full.min.js。 它應該解決它! :)

您正在使用舊版本的日期選擇器js。 使用最新版本升級datepicker js。

用這將替換你的bootstrap-datetimepicker.min.js文件..

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/3.1.3/js/bootstrap-datetimepicker.min.js"></script>

我有這個問題。 我的解決方案是刪除Vue.js文件的鏈接。 Vue.js和JQuery在datepicker和datetimepicker函數中有一些沖突。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM