【发布时间】:2015-09-22 12:53:32
【问题描述】:
我正在尝试通过this 链接为我的项目使用 jQuery 的 Datatable JS。
我从同一来源下载了完整的库。包中给出的所有示例似乎都可以正常工作,但是当我尝试将它们合并到我的 WebForms 中时,CSS、JS 根本就工作。
这是我所做的:
<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 的文件结构如下所示:
我已经添加了所有必要的 JS 和 CSS 参考,如手册中所示。渲染仍然不如预期。没有CSS,连JS都不行。
在控制台中我也收到以下错误:
ReferenceError: jQuery is not defined
TypeError: $(...).DataTable is not a function
我还没有在此处绑定任何动态数据(例如在中继器内),但它仍然无法正常工作。
有人可以指导我解决这个问题的正确方向吗?
【问题讨论】:
-
无论我写什么代码都很好,但我也遇到了同样的错误。经过长时间的分析,我刚刚重新启动了我的电脑,因为我最近 7 天没有重新启动。然后,我的代码开始工作了。
-
@Ashokkumar:你可能走运了!
标签: javascript jquery css asp.net datatables