简体   繁体   English

根据 select 值筛选表行数

[英]Filter table number rows based on select value

For example: Choose 4 -> display 4 rows, choose 6 -> display 6 rows例如: Choose 4 -> display 4 rows, choose 6 -> display 6 rows

option value will be number not string选项值将是数字而不是字符串

<option value="4">4</option> not <option value="4">4</option>不是

<option value="a1">4</option>

 $('.filter-handle').on('change', function(e) { var $rows = $('#table').find('tr'); var showRow = Number(e.target.value)+1; $rows.hide().slice(0, showRow).show(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select class="filter-handle"> <option value="4">4</option> <option value="6">6</option> <option value="8">8</option> </select> <table class="filter-table-data" id="table"> <tr><th scope="col">Name</th><th scope="col">Des</th></tr> <tr><td>Vu Tran</td><td>Sunnyvale</a></tr> <tr><td>Michelle Case</td><td>Sunnyvale</a></tr> <tr><td>Todd Linden</td><td>Madison</a></tr> <tr><td>Michael Liston</td><td>Madison</a></tr> <tr><td>Vu Tran</td><td>Sunnyvale</a></tr> <tr><td>Michelle Case</td><td>Sunnyvale</a></tr> <tr><td>Todd Linden</td><td>Madison</a></tr> <tr><td>Michael Liston</td><td>Madison</a></tr> <tr><td>Vu Tran</td><td>Sunnyvale</a></tr> <tr><td>Michelle Case</td><td>Sunnyvale</a></tr> <tr><td>Todd Linden</td><td>Madison</a></tr> <tr><td>Michael Liston</td><td>Madison</a></tr> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM