我找到了 this question on StackOverflow有一个很好的答案,但作为初学者,我想要更详细的解释,因为我的情况有点不同:我有一张如下所示的表格:
________________________________________________
| id | name | age | location |
|----+--------------+-----+--------------------|
| 1 | Victor | 14 | Bucharest, Romania |
| 2 | John | 17 | New York, USA |
| 3 | Steve | 12 | New York, USA |
| 7 | Michael | 37 | Washington DC, USA |
| 9 | Michaela | 25 | Washington DC, USA |
|----+--------------+-----+--------------------|
这个人的id在我的数据库(MySQL数据库)中设置为AUTO_INCREMENT
,所以如果我删除一条记录,它会像我这里表中的最后一条(从7到9 ).我想在我的 HTML 表中搜索包含 personId = 3
的行。
因此,基于 the question in my link ,我怎样才能将该搜索优化为仅在 ID 列中?
为@yeyene 编辑:
这是基于您的代码的功能。实际上,我不需要更改行的背景颜色,我需要行的索引以便稍后使用 .eq(index)
对其进行一些操作:
function findTableRow(personId){
$('#people tr').each(function(){
if($(this).find('td').eq(0).text() == personId){
return (row's index?)
}
});
}
最佳答案
点击此处,DEMO http://jsfiddle.net/yeyene/wAxNu/
$(document).ready(function(){
$('table tr').each(function(){
if($(this).find('td').eq(0).text() == '3'){
$(this).css('background','red');
}
});
});
关于jquery - 使用 jQuery 在 COLUMN 中搜索表行以查找特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17875119/