我有以下HTML源代码
<tr>
<td>Peter Pan</td>
<td>Nervland</td>
<td>
<a href="edit/id-for-peterP">edit</a>
<a href="delete/id-for-peterP">delete</a>
</a></td>
</tr>
<tr>
<td>Wendy</td>
<td>Nervland</td>
<td>
<a href="edit/id-for-wendy">edit</a>
<a href="delete/id-for-wendy">delete</a>
</a></td>
</tr>
任务是
选择同时包含“Peter Pan”
的单元格的行中的编辑链接
我如何(有效地)解决这个问题?
答案 0 :(得分:1)
选择包含字符串Peter Pan
的行,然后找到以edit
开头的href属性的链接并将其设为红色:
$('tr:contains("Peter Pan") a[href^=edit]').addClass('red');
.red { color:red }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<tr>
<td>Peter Pan</td>
<td>Nervland</td>
<td>
<a href="edit/id-for-peterP">edit</a>
<a href="delete/id-for-peterP">delete</a>
</td>
</tr>
<tr>
<td>Wendy</td>
<td>Nervland</td>
<td>
<a href="edit/id-for-wendy">edit</a>
<a href="delete/id-for-wendy">delete</a>
</td>
</tr>
</table>
答案 1 :(得分:0)
使用此代码:
$( "td:contains('Peter Pan')");
答案 2 :(得分:0)