我想初始化我的DataTables,我已经下载了它,调用它,一切看起来都还好,但是当我调用JQuery函数来运行数据时,它给了我这个奇怪的错误。
TypeError:$不是函数
但我的代码似乎没问题:
$(document).ready( function () {
$('#table_id').DataTable();
} );
THis是我的HTML:
<table id="table_id" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
</tbody>
这能是什么?
脚本顺序:
发布于 2018-10-21 21:14:53
TypeError:$不是函数
这意味着javascript没有识别jquery。
要解决这个问题,需要在脚本代码之前包含jquery。所以应该是这样的:
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script>
$(document).ready( function () {
$('#table_id').DataTable();
});
</script>
发布于 2018-10-21 20:52:39
我不能发表评论,因为我是新手。所以,您的问题不是datatable,而是jQuery。正如注释中所述,在使用jquery语法之前,必须导入jQuery。在项目中将jquery与cdn或导入库结合使用。
https://stackoverflow.com/questions/52919730
复制相似问题