我正在尝试匹配以下HTML中的父级
<tbody>
<tr id="group-1" class="group">
<td>
<div class="GroupHeader">
Group1 <span class="CriteriaEditOptions"><a id="EditGroupItem" href="/Template/EditGroupItem?GroupID=1">Edit</a></span> <span class="CriteriaMoveUp"><a href="/Template/GroupMovePosition?GroupID=1&MoveType=0&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a></span> <span class="CriteriaMoveDown"><a href="/Template/GroupMovePosition?GroupID=1&MoveType=1&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a></span> <span class="GroupDelete"><a href="/Template/DeleteGroup?GroupID=1&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a></span>
</div>
<table>
<tbody>
<tr id="1" class="selection">
<td>
Number1 <span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=1">Edit</a></span> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=1&MoveType1=0&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=1&MoveType1=1&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> <a href="/Template/DeleteCriteriaItem?CriteriaItemID=1&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a>
</td>
</tr>
<tr id="2" class="selection">
<td>
Price2 <span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=2">Edit</a></span> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=2&MoveType1=0&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=2&MoveType1=1&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> <a href="/Template/DeleteCriteriaItem?CriteriaItemID=2&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a>
</td>
</tr>
<tr id="3" class="selection">
<td>
Single Line Text3 <span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=3">Edit</a></span> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=3&MoveType1=0&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=3&MoveType1=1&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> <a href="/Template/DeleteCriteriaItem?CriteriaItemID=3&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a>
</td>
</tr>
<tr id="4" class="selection">
<td>
Single Line Text4 <span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=4">Edit</a></span> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=4&MoveType1=0&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=4&MoveType1=1&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> <a href="/Template/DeleteCriteriaItem?CriteriaItemID=4&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a>
</td>
</tr>
<tr id="5" class="selection">
<td>
Single Line Text5 <span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=5">Edit</a></span> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=5&MoveType1=0&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=5&MoveType1=1&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> <a href="/Template/DeleteCriteriaItem?CriteriaItemID=5&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a>
</td>
</tr>
<tr id="6" class="selection">
<td>
Number6 <span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=6">Edit</a></span> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=6&MoveType1=0&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> <a href="/Template/CriteriaItemMovePosition?CriteriaItemID=6&MoveType1=1&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> <a href="/Template/DeleteCriteriaItem?CriteriaItemID=6&rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
我位于
<div class="GroupHeader">
我正在尝试匹配
的父母<tr id="group-1" class="group">
有没有办法在jquery中执行此操作?我已尝试使用parent()
,但无效
答案 0 :(得分:4)
您可以使用closest('tr')
获取与提供的选择器匹配的第一个父级。
答案 1 :(得分:2)
.parents('tr')
向上寻求
答案 2 :(得分:2)
parent
只看一级。使用parents
查看多个级别。
$current.parents("#group-1 .group")