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

查看:152
本文介绍了TypeError:$(...)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

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

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