以为这会很容易,但是我遇到了麻烦!
我有一个表,当我根据一个名称在该表中搜索一行时,我要突出显示找到的行。我正在尝试以下代码:
var elem = $("#table-names tr:contains("+ name +")");
$(elem).css("background-color", "red");
但这是行不通的。
编辑(以下html):
<table id="table-names" class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th align="center">Pos</th>
<th align="center">Name</th>
<th align="center">Points</th>
</tr>
</thead>
<tbody>
<?php
$rows = getPoints();
foreach ($rows->body as $row):
?>
<tr>
<td><?= $row->position; ?></td>
<td><?= $row->teamshort; ?></td>
<td><?= $row->points; ?></td>
</tr>
<? endforeach ?>
</tbody>
</table>
我想念什么吗?
干杯
最佳答案
:contains()
括号内的文本需要用引号引起来。
它应该是
var elem = $("#table-names tr:contains('"+ name +"')");
More information here.