【发布时间】:2014-08-12 06:34:25
【问题描述】:
我有一个 jQuery 脚本,可以过滤具有许多列的 html 表,我只需要能够根据用户输入显示所有行,但只希望表的过滤应该通过用户选择的特定列下拉列表
jQuery 代码
$(document).ready(function(){
$("#kwd_search").keyup(function(){
var term=$(this).val()
if( term != "")
{
$("#my-table tbody>tr").hide();
$("#my-table td").filter(function(){
return $(this).text().toLowerCase().indexOf(term ) >-1
}).parent("tr").show();
$("#my-table tbody>tr th").show();
}
else
{
$("#my-table tbody>tr").show();
}
});
});
HTML 代码
<select id="clmn_name">
<option>Column 1</option>
<option>Column 2</option>
<option>Column 3</option>
</select>
<input id="kwd_search" placeholder="Search Me">
<table id="my-table">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apple</td>
<td>Orange</td>
<td>Mango</td>
</tr>
<tr>
<td>Strawberry</td>
<td>Banana</td>
<td>Cherry</td>
</tr>
</tbody>
</table>
那么如何根据用户选择的表格列过滤返回的HTML代码呢?
【问题讨论】:
-
我也在寻找同样的解决方案.....
-
那么它工作正常的问题是什么?
-
我猜这个问题有你需要的。 stackoverflow.com/questions/455958/…