如何仅显示与jquery文本框中输入的值相同的表的行?

How can I show only the row of a table that has the same value that was entered in a textbox with jquery

本文关键字:输入 显示 何仅 jquery 文本      更新时间:2023-09-26

我有一个排名表,我输入排名的ID,它只显示这一行作为我的代码的列行:

$('button').click(function () {
var data = $("textarea").val(); 
var rank = $("#rank").val(); 
if(rank == ""){
    alert("digit rank number");
}
else{
data = data.replace(/'s/, " #"); 
data = data.replace(/([0-9]'s)/g, "$1#"); 
var lines = data.split("#"), 
    output = [],
    i;
for (i = 0; i < lines.length; i++)
    output.push("<tr><td>" + lines[i].slice(0,-1).split(",").join("</td><td>") + "</td></tr>");
output = "<table>" + output.join("") + "</table>";
var valuefinal = $(output).find('tr').filter(function(){ 
    return $(this).children('td').eq(1).text() == rank;
});
 $('#fileDisplayArea').html(valuefinal);
}
});

我在那部分代码中做这个过滤器

var valuefinal = $(output).find('tr').filter(function(){ 
        return $(this).children('td').eq(1).text() == rank;
    });
     $('#fileDisplayArea').html(valuefinal);

演示代码如果你听不懂,请原谅我,我的英语很烂。我希望你清楚我需要什么

你需要改变这个-

return $(this).children('td').eq(1).text() == rank;

to this -

return $(this).children('td').eq(0).text() == rank;

.eq()是一个从零开始的数组方法。

http://jsfiddle.net/jayblanchard/qM6Fj/19/

http://api.jquery.com/eq/

您需要有一个搜索功能,您已经在表中显示的内容是我得到.....你可以使用jQuery DataTable来完成这个任务link ..向下滚动查看带有排序、搜索等功能的表显示