基于用户输入的jquery表行选择器 [英] jquery table row selector based on user input
本文介绍了基于用户输入的jquery表行选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何根据输入框中的内容选择行? 这是我到目前为止的内容:
How do I select rows depending on what's in an input box? Here's what I have so far:
<html>
<head>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#btnFilter').keyup(function() {
var myInput = $(this).val();
$('tbody tr').hide();
// I need to .show() all table rows that have a table cell with a value that begins with the input field.
$('tr').something goes here.show();
});
});
</script>
</head>
<body>
<form>
<input id="btnFilter" name="btnFilter">
</form>
<table>
<thead>
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>X</td>
</tr>
<tr>
<td>ABC</td>
<td>D</td>
</tr>
</tbody>
</table>
</body>
</html>
推荐答案
如果您要搜索,请 :contains()
可能就是您想要的,例如:
If you want a search, :contains()
is probably what you're after, for example:
$('tr:contains("' + myInput + '")').show();
您可以在此处尝试,或者仅使用单元格开始版本:>
You can try it out here, or a cell-begins-with only version:
$('td').filter(function() {
return $.text([this]).indexOf(myInput) == 0
}).parent().show();
这篇关于基于用户输入的jquery表行选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文