Javascript DataTable 不是 DataTables JQuery 库的函数错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32315701/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 07:52:37  来源:igfitidea点击:

DataTable is not a function error with DataTables JQuery library

javascriptjqueryhtmldatatables

提问by user2242044

I have a simple example of using the Datatable library. I have it working with JSFiddle (http://jsfiddle.net/3hhn7y7f/), but when I try to do it with actual files I get the following errors. I have JQuerydefined in the <script>tag so I don't know what the issue is.

我有一个使用 Datatable 库的简单示例。我将它与 JSFiddle ( http://jsfiddle.net/3hhn7y7f/) 一起使用,但是当我尝试使用实际文件执行此操作时,出现以下错误。我JQuery<script>标签中定义了所以我不知道问题是什么。

Uncaught ReferenceError: jQuery is not defined

Uncaught ReferenceError: jQuery is not defined

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

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

HTML file

HTML文件

<html>
<head>
 <script type="text/javascript" src="https://cdn.datatables.net/1.10.8/js/jquery.dataTables.min.js"></script>
 <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
 <script type="text/javascript" src="script.js"></script>
 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.8/css/jquery.dataTables.min.css">
</head>
<body>
<table id="example" class="display" width="100%"></table>

 </body>
 </html>

script.js

脚本.js

var dataSet = [
    [ "Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "0,800" ],
    [ "Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "0,750" ],
    [ "Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", ",000" ],
    [ "Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "6224", "2012/03/29", "3,060" ]
];

$(document).ready(function() {
    $('#example').DataTable( {
        data: dataSet,
        columns: [
            { title: "Name" },
            { title: "Position" },
            { title: "Office" },
            { title: "Extn." },
            { title: "Start date" },
            { title: "Salary" }
        ]
    } );
} );

回答by jonmrich

You likely need to switch the order of the <script>tags.

您可能需要切换<script>标签的顺序。

Put this one:

放这个:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

BEFORE this one:

在此之前:

<script type="text/javascript" src="https://cdn.datatables.net/1.10.8/js/jquery.dataTables.min.js"></script>

That is, define jQuery before you define DataTables.

也就是说,在定义数据表之前定义 jQuery。