I am trying to work with jQuery's Datatable JS for my project from this link.

I downloaded the complete library from the same source. All the examples given in the package seem to work fine, but when I try to incorporate them in my WebForms,the CSS,JS do not work at all.

以下是我所做的:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table id="myTable" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </tfoot>
            <tbody>
               <!-- table body -->
            </tbody>
        </table>
    </div>
    <script src="js/jquery.dataTables.js" type="text/javascript"></script>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#myTable').DataTable();
        });
    </script>
    </form>
</body>
</html>

My file structure for the JS and CSS in my Solution looks as follows :

解决方案中JS和CSS的文件 struct

I have added all the necessary JS and CSS references as shown in the manual. Still the rendering isn't as expected. There is no CSS and even the JS doesn't work.

在控制台中,我还收到以下错误:

ReferenceError: jQuery is not defined
TypeError: $(...).DataTable is not a function

我仍然没有在这里绑定任何动态数据(比如在中继器内),但它仍然不起作用.

有人能为我指出解决这个问题的正确方向吗?

推荐答案

原因

There could be multiple reasons for this error.

  • jQuery DataTables library is missing.
  • jQuery库加载了after个jQuery数据表.
  • Multiple versions of jQuery library is loaded.

解决方案

Include only one version of jQuery library version 1.7 or newer before jQuery DataTables.

例如:

<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.min.js" type="text/javascript"></script>

有关此错误和其他常见控制台错误的详细信息,请参见jQuery DataTables: Common JavaScript console errors.

Jquery相关问答推荐

这是否会导致内存泄漏?

如何从 jQuery 转到 React.js?

jquery数据表隐藏列

如何在 bootstrap 模式关闭并重新打开时重置 bootstrap 模式?

jQuery切换CSS?

一次替换多个字符串

window.onbeforeunload 和 window.onunload 在 Firefox、Safari、Opera 中不起作用?

禁用 Android 网页中输入焦点的zoom

隐藏 div 但保留空白

CORS POST 请求可以使用纯 JavaScript,但为什么不使用 jQuery?

按文本 Select 链接(完全匹配)

判断 JS 对象中是否存在键

jQuery ajax 成功回调函数定义

jQuery从字符串中删除'-'字符

如何在纯 JavaScript 中模拟鼠标悬停以激活 CSS:悬停?

如何在 DOM 中移动 iFrame 而不会丢失其状态?

粘性侧边栏:向下滚动时固定在底部,向上滚动时固定在顶部

Jquery 日期 Select 器 z-index 问题

jQuery append() 与 appendChild()

使用 jQuery 将一个标签替换为另一个标签