jquery - DataTables() 不是函数
问题描述
我在使用 DataTables 时遇到问题:
我已经使用cdn导入了它:
<link rel="stylesheet" href="./assets/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.20/datatables.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.20/datatables.min.js"></script>
我有一个“DataTable”的脚本:
<script type="text/javascript">
$(document).ready(function() {
$('#dataTableUser').DataTable();
});
但我总是收到以下错误:
zone-evergreen.js:172 Uncaught TypeError: $(...).DataTable is not a function
这是我的html页面:
<div style="margin-top: 30px" id="wrapper">
<div class="d-flex flex-column" id="content-wrapper">
<div id="content">
<div class="container-fluid">
<div class="card shadow">
<div class="card-body">
<div class="row">
<div class="table-responsive table mt-2" id="dataTableUser" role="grid" aria-describedby="dataTable_info">
<table class="table dataTable my-0" id="dataTable">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>P.IVA</th>
<th>C.Fiscale</th>
<th>Approva</th>
<th>Rifiuta</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let user of users">
<td><a href="/back/(secondRouter:back-profilo)?id={{ user.id_user }}">{{ user.user_name }}</a></td>
<!-- <td><a (click)="navigate2()">{{ user.user_name }}</a></td> -->
<td>{{ user.email }}</td>
<td>{{ user.vat }}</td>
<td>{{ user.cod_fisc }}<br></td>
<td><i style="margin-left: 15%" class="fa fa-check"></i></td>
<td><i style="margin-left: 15%" class="fa fa-times-circle" aria-hidden="true"></i></td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Username</th>
<th>Email</th>
<th>P.IVA</th>
<th>C.Fiscale</th>
<th>Approva</th>
<th>Rifiuta</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
</div>
解决方案
您正在使用 div 中的 id 而不是表中的 id。
尝试这个:
$(document).ready(function() {
$('#dataTable').DataTable();
});
推荐阅读
- ssis - SSIS SQL 任务不会从 XML 列返回结果
- javascript - Meyda 特征提取的 dat 在命令行和通过 nodejs 是不同的
- python - ValueError:无法将大小为 12400 的数组重塑为形状 (1,4)
- c# - 在具有附加条件的子列表上应用日期过滤器c#Linq
- android - Android 11 更新对已获得的持久权限的影响
- pandas - 重塑数据框 pandas
- laravel - npm 错误!代码 ENOENT npm 错误!系统调用打开
- flutter - Flutter/Dart 语法 - 使用?
- c# - 如何以编程方式查看旧 Access 数据库的 VBA 代码?
- azure - Azure Frontdoor 为通配符域配置子域模式