【发布时间】:2018-12-14 04:05:26
【问题描述】:
我想在表的 State 列中添加搜索和过滤功能,最好使用 jquery。
这是表格的代码。
<div id="container">
<div class="table-responsive">
<p>
Search: <input type="text" id="table-filter" value="">
</p>
<table id ="table" class="table table-striped">
<thead>
<tr>
<th> First Name </th>
<th> Last Name </th>
<th> State </th>
<th> Date of Birth</th>
<th> Action </th>
</tr>
</thead>
<?php
if (count($report) === 0) {
echo "<tr>No Reports</tr>";
} else {
for ($i = 0; $i < count($report); $i++) {
echo
"<tr>
<td>{$report[$i]['First_Name']}</td>
<td>{$report[$i]['Last_Name']}</td>
<td>{$report[$i]['State']}</td>
<td>{$report[$i]['Date_of_Birth']}</td>
<td><a class=btn href='read.php?id=".$read['Id']."'>Read</a></td>
</tr>";
}
}
?>
</table>
</div>
</div>
main.js
$(document).ready(function(){
$("#table-filter").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#table").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
我对 jquery 很陌生。任何帮助将不胜感激。
【问题讨论】:
-
如果您是新人,请做一些 tuto 而不是要求 anwser :) 尝试一些东西,如果您做不到,请告诉我们!