gpt4 book ai didi

javascript - jQuery DataTables 功能不可用

转载 作者:行者123 更新时间:2023-11-30 19:35:07 25 4
gpt4 key购买 nike

我的 DataTables 插件有问题,我已经设法让它在另一个项目中工作,但在这个项目中它不起作用,我不知道为什么。

似乎只有 jQuery 部分不起作用,因为我已经有了 CSS 元素,并且带有 DataTable 函数的函数起作用了,但是当我尝试使用搜索输入或按列排序时什么也没发生我的 table

这是我的 HTML/PHP:

<!DOCTYPE html>
<html lang="fr">

<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Formulaire de recherche bitrix24</title>

<link rel="stylesheet" href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/styles.css">

</head>

<body>
.......
.......

<div class="container-fluid">
<div class="row">
<div class="offset-3"></div>
<div class="col-lg-8">
<table class="table table-hover table-responsive display" id="table_1">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Titre</th>
<th scope="col">Prénom</th>
<th scope="col">Prospect créé le </th>
</tr>
</thead>
<?php
foreach($result as $key1){
?>
<tbody>
<tr>
<th scope="row"><?php echo $key1['ID']; ?></th>
<td><?php echo $key1['TITLE']; ?></td>
<td><?php echo $key1['NAME']; ?></td>
<td><?php $date_create=$key1['DATE_CREATE']; echo strftime("%A %e %B %Y à %H h %M ", strtotime($date_create)); ?>
</td>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
</div>
</div>
......
......

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>



</body>

</html>

这是我在另一个文件 (js/scripts.js) 中的 js 部分

$(document).ready(function(){
$('#table_1').DataTable({
"bDestroy": true,
language: {
processing: "Traitement en cours...",
search: "Rechercher&nbsp;:",
lengthMenu: "Afficher _MENU_ &eacute;l&eacute;ments",
info: "Affichage de l'&eacute;lement _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
infoEmpty: "Affichage de l'&eacute;lement 0 &agrave; 0 sur 0 &eacute;l&eacute;ments",
infoFiltered: "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
infoPostFix: "",
loadingRecords: "Chargement en cours...",
zeroRecords: "Aucun &eacute;l&eacute;ment &agrave; afficher",
emptyTable: "Aucune donnée disponible dans le tableau",
paginate: {
first: "Premier",
previous: "Pr&eacute;c&eacute;dent",
next: "Suivant",
last: "Dernier"
},
aria: {
sortAscending: ": activer pour trier la colonne par ordre croissant",
sortDescending: ": activer pour trier la colonne par ordre décroissant"
}
}
});


});

这是我所拥有的: https://i.ibb.co/fkBdx51/Capture.png

enter image description here

所以,我拥有所有 CSS 元素,我的表格可以很好地被我的 jQuery 函数识别,但是没有一个 JS 元素像上面所说的那样工作。

有人可以帮我解决这个问题吗?

最佳答案

好的,我刚刚解决了这个问题,我的 foreach 循环不在正确的位置,它正在创建多个 tbody 标签。

我改变了循环的位置,现在它可以工作了。

关于javascript - jQuery DataTables 功能不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56021700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com