使用 [[jQuery]] [[filter]] API 对 [[HTML]] 表格进行过滤
<div class="w3-padding w3-white notranslate" style="width:100%"><div style="width:100%"> <p style="margin-top:14px">Type something in the input field to search the table for first names, last names or emails:</p> <input id="myInput" type="text" placeholder="Search.."> <br> <table class="ws-table-all"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody id="myTable"> <tr> <td>John</td> <td>Doe</td> </tr> <tr> <td>Mary</td> <td>Moe</td> </tr> <tr> <td>July</td> <td>Dooley</td> </tr> <tr> <td>Anja</td> <td>Ravendale</td> </tr> </tbody> </table></div></div>
$(document).ready(function(){ $("#myInput").on("keyup", function() { var value = $(this).val().toLowerCase(); $("#myTable tr").filter(function() { $(this).toggle( $(this).text().toLowerCase().indexOf(value) > -1 ); }); });});