类型错误:$(...)DataTable 不是函数 [英] TypeError: $(...)DataTable is not a function

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

问题描述

我正在尝试使用 jquery 插件数据表,但我似乎无法加载该功能.我不断收到此错误:

I am trying to use the jquery plugin data tables, but I can't seem to load the function. I keep getting this error:

Uncaught TypeError: $(...).DataTable is not a function
(anonymous function) @ index.php:167
m.Callbacks.j @ jquery.min.js:2
m.Callbacks.k.fireWith @ jquery.min.js:2
m.extend.ready @ jquery.min.js:2
J @ jquery.min.js:2

下面是我的JS代码:

$(document).ready(function(){
        $('table#tableID').DataTable({
            paging: true
        });
    });

我使用的是 jQuery V.1.11.1我试图环顾四周寻找解决方案,看到人们在谈论 jQuery 没有被加载.我在同一页面上成功运行其他 jQuery 函数.这也是此页面上唯一的 .ready 函数.我们可以看出 jQuery 存在,因为当文档准备好时,它会执行该函数.我还尝试按照建议将 js 和 css 文件的导入放置在多个位置,但没有奏效.有没有人知道如何解决这个问题?

I am using jQuery V. 1.11.1 I tried to look around for solution, and saw people talking about jQuery not being loaded. I am running other jQuery functions on the same page successfully. This is also the only .ready function on this page. We can tell that jQuery is present, as when the document is ready, it executes the function. I also tried to place the imports of the js and css file in multiple places, as suggested, but did not work. Does anyone have any clue how to fix this?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="/js/jquery.dataTables.js"></script>

推荐答案

当脚本依赖于库或其他脚本时,脚本的顺序很重要.

Order of scripts is important when they are dependent on libraries or other scripts.

任何与 jQuery 相关的代码都需要包含在 jQuery.js 之后……这意味着插件和您编写的任何使用 jQuery 的代码.同样,您编写的任何使用插件的代码都必须在您的代码之前加载插件

Any jQuery related code needs to be included after jQuery.js... that means plugins and any code you write that uses jQuery. Similarly any code you write that uses a plugin must have the plugin loaded before your code

只需切换顺序,使 jQuery.js 在 dataTables.js 之前加载

Simply switch the order so jQuery.js loads before dataTables.js

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" charset="utf8" src="/js/jquery.dataTables.js"></script>

还要确保你在一个页面中只包含一次 jQuery...而不是每个插件一次,因为有些人偶尔会这样做

Also make sure you only ever include jQuery once in a page...not once per plugin as some occasionally do

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

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