基于用户输入的jquery表行选择器

基于用户输入的jquery表行选择器,jquery,Jquery,如何根据输入框中的内容选择行? 以下是我目前掌握的情况: <html> <head> <script src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("jquery", "1"); </script> <script type="text/javascript"> $(document)

如何根据输入框中的内容选择行? 以下是我目前掌握的情况:

<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>

load(“jquery”,“1”);
$(文档).ready(函数(){
$('#btnFilter').keyup(函数(){
var myInput=$(this.val();
$('tbody tr').hide();
//我需要.show()所有具有以输入字段开头的值的表格单元格的表格行。
$('tr')。这里有东西。show();
});
});
标题1
标题2
A.
X
基础知识
D
如果您想要搜索,可能就是您想要的,例如:

$('tr:contains("' + myInput + '")').show();
,或单元格仅以版本开头:

$('td').filter(function() {
  return $.text([this]).indexOf(myInput) == 0
}).parent().show();

.

这不是一个直接的答案,但如果您正在寻找一种筛选表的方法,请查看。它在jQuery中,直接使用html表结构,支持分页、过滤、排序等。这是一个很棒的插件。Zounds!嘿,尼克!你在W-S?!我在山核桃里!蜜月过得怎么样?@cf_PhillipSenn-好极了:)本周也想买房子;)
$(document).ready(function() {
    $('#btnFilter').keyup(function() {
        var myInput = $(this).val();
        $('tbody tr').hide().find('td:contains("'+myInput+'")').parents('tr:first').show()
    });
});