DataTable不是DataTables JQuery库的函数错误 [英] DataTable is not a function error with DataTables JQuery library

查看:56
本文介绍了DataTable不是DataTables JQuery库的函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 JQuery defined in the <script> tag so I don't know what the issue is.

Uncaught ReferenceError: jQuery is not defined

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

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

script.js

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

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

推荐答案

您可能需要切换<script>标记的顺序.

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

放置一个:

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

在此之前:

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

也就是说,在定义DataTables之前先定义jQuery.

That is, define jQuery before you define DataTables.

这篇关于DataTable不是DataTables JQuery库的函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆