TypeError:$(...)。DataTable不是一个函数 [英] TypeError: $(...).DataTable is not a function
问题描述
我正在尝试通过此链接为我的项目使用jQuery的Datatable JS。
I am trying to work with jQuery's Datatable JS for my project from this link.
我从同一个源下载完整的库。包中给出的所有示例似乎都可以正常工作,但是当我尝试将它们并入到我的 WebForms
中时,CSS,JS不会工作。 / strong>
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>
我的解决方案中的JS和CSS的文件结构如下所示:
My file structure for the JS and CSS in my Solution looks as follows :
我已经添加了所有必需的JS和CSS引用,如手册中所示。仍然渲染不如预期。没有CSS,甚至JS不起作用。
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.
另外在控制台中我收到以下错误:
Also in the console i get the following errors:
ReferenceError: jQuery is not defined
TypeError: $(...).DataTable is not a function
我仍然没有绑定任何动态数据(像在一个中继器之内)仍然没有工作。
I have still not bound any dynamic data here (like within a repeater or so) still it is not working.
有人可以指导我正确的方向来解决这个问题吗?
Can someone please guide me in the right direction for this problem ?
推荐答案
您需要在之前加载jQuery ,您可以加载任何与jQuery数据表相关的jQuery相关代码,如下所示:
You need to load jQuery before you load any jQuery-related code such as jQuery DataTables, see below:
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.js" type="text/javascript"></script>
此外,对于生产版本,建议加载最小化版本(以$ code结尾)。 min.js 代替)。
Also, for production version it's recommended to load minified version (ending with .min.js
instead).
这篇关于TypeError:$(...)。DataTable不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!