如何在表中搜索?
问题描述:
我搜索使用下表以及较低和大写搜索过滤器JavaScript的任何帮助将不胜感激怎么办谢谢:)如何在<tr>表中搜索?
<div class="title">
<h3>Products</h3>
</div>
<table class="list">
<thead>
<tr>
<th class="left">List A</th>
<th class="right">List B</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td class="left">apple</td>
<td class="rightt">100</td>
</tr>
<tr>
<td class="left">snapple</td>
<td class="right">200</td>
</tr>
</tr>
</tbody>
</table>
答
在此请看:http://jsfiddle.net/csdtesting/w3f9gx5c/
var $rows = $('.list tr');
$('#search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="search" placeholder="Type to search" />
<table class="list">
<tbody class="table-hover">
<tr>
<td class="left">apple</td>
<td class="rightt">100</td>
</tr>
<tr>
<td class="left">snapple</td>
<td class="right">200</td>
</tr>
<tr>
<td class="left">SNAPPLE</td>
<td class="right">200</td>
</tr>
<tr>
<td class="left">APPLE</td>
<td class="right">200</td>
</tr>
</tr>
</tbody>
</table>
答
$('tr td:contains("text to search for")') //returns all td tags that have the text you enter
+0
你能给我的全部代码搜索,请这将是非常有帮助的感谢 –
YoiMCoding
2014-10-04 00:13:14
+0
这是字面上的。 –
DLeh
2014-10-04 00:14:08
+0
http://jsfiddle.net/e0unsvz3/我做错了什么? –
YoiMCoding
2014-10-04 00:16:05
我搜索使用下表以及较低和大写搜索过滤器JavaScript的任何帮助将不胜感激怎么办谢谢:)如何在<tr>表中搜索?
<div class="title">
<h3>Products</h3>
</div>
<table class="list">
<thead>
<tr>
<th class="left">List A</th>
<th class="right">List B</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td class="left">apple</td>
<td class="rightt">100</td>
</tr>
<tr>
<td class="left">snapple</td>
<td class="right">200</td>
</tr>
</tr>
</tbody>
</table>
在此请看:http://jsfiddle.net/csdtesting/w3f9gx5c/
var $rows = $('.list tr');
$('#search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="search" placeholder="Type to search" />
<table class="list">
<tbody class="table-hover">
<tr>
<td class="left">apple</td>
<td class="rightt">100</td>
</tr>
<tr>
<td class="left">snapple</td>
<td class="right">200</td>
</tr>
<tr>
<td class="left">SNAPPLE</td>
<td class="right">200</td>
</tr>
<tr>
<td class="left">APPLE</td>
<td class="right">200</td>
</tr>
</tr>
</tbody>
</table>
$('tr td:contains("text to search for")') //returns all td tags that have the text you enter
你能给我的全部代码搜索,请这将是非常有帮助的感谢 – YoiMCoding 2014-10-04 00:13:14
这是字面上的。 – DLeh 2014-10-04 00:14:08
http://jsfiddle.net/e0unsvz3/我做错了什么? – YoiMCoding 2014-10-04 00:16:05
解释downvote plz! – 2014-10-04 00:16:43
@mia是你在找什么? – 2014-10-04 00:22:50
我可以说我爱你hehehhe谢谢soo muchhh :)))))))))你让我的一天感谢洛特工作像charmmm – YoiMCoding 2014-10-04 00:41:33