Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选择表行的更好方法?_Javascript_Jquery - Fatal编程技术网

Javascript 选择表行的更好方法?

Javascript 选择表行的更好方法?,javascript,jquery,Javascript,Jquery,我有以下(简化的)表格结构: <table class="form-table"> <tbody> <tr> <tr><--Need to select and add class on this guy based on h3 class "check"--> <th scope="row"> <h3 class="check">Default Checbox:</h3> </th> &

我有以下(简化的)表格结构:

<table class="form-table">
<tbody>
<tr>
<tr><--Need to select and add class on this guy based on h3 class "check"-->
<th scope="row">
<h3 class="check">Default Checbox:</h3>
</th>
<td>
</tr>
</tbody>
</table>
但问题是,为了做出选择,我给了一个不必要的类“酷”

<table class="form-table">
<tbody>    
<tr>
<tr>
<tr class="until"><--Class successfully added but..-->
<th class="cool" scope="row"><--An extra Class in order to select "table row"-->
<h3 class="check">Default Checbox:</h3>
</th>
<td>
</tr>
</tbody>
</table>

默认复选框:
有没有更好的方法来实现这一点(不添加不必要的类)

您可以使用


@佩德罗斯特拉达在打给你我知道这很简单:=)你让我开心。THX.
'tbody'
选择器是多余的,因为每个TR都是tbody的子项(无论标记是否包含在标记中)。
<table class="form-table">
<tbody>    
<tr>
<tr>
<tr class="until"><--Class successfully added but..-->
<th class="cool" scope="row"><--An extra Class in order to select "table row"-->
<h3 class="check">Default Checbox:</h3>
</th>
<td>
</tr>
</tbody>
</table>
$('tbody tr').has('h3.check').addClass('cool');
$('tbody tr:(h3.check)').addClass('cool');