Javascript jQuery查找TR->;TH值(s)

Javascript jQuery查找TR->;TH值(s),javascript,jquery,html,wildcard,Javascript,Jquery,Html,Wildcard,嘿,我这里有以下jquery代码: $('th[id*="headingData_"]').each(function () { fieldNames += $(this).data("dbname") + '~'; console.log(fieldNames); }) 这是我从中提取数据的HTML: <tr role="row"> <th id="headingData_0" data-dbname="F_FName" class="sorting_

嘿,我这里有以下jquery代码:

$('th[id*="headingData_"]').each(function () {
    fieldNames += $(this).data("dbname") + '~';
    console.log(fieldNames);
})
这是我从中提取数据的HTML:

<tr role="row">
   <th id="headingData_0" data-dbname="F_FName" class="sorting_asc" tabindex="0" 
       aria-controls="theDataTable" rowspan="1" colspan="1" aria-sort="ascending" 
       aria-label="First Name: activate to sort column ascending" 
       style="width: 557px;">First Name
   </th>
   <th id="headingData_1" data-dbname="F_LName" class="sorting" tabindex="0"
       aria-controls="theDataTable" rowspan="1" colspan="1" 
       aria-label="Last Name: activate to sort column ascending" 
       style="width: 557px;">Last Name
   </th>
   <th class="sorting" tabindex="0" aria-controls="theDataTable" rowspan="1" 
       colspan="1" aria-label="Action: activate to sort column ascending" 
       style="width: 438px;">Action
   </th>
</tr>

名字
姓
行动
上面的jQuery代码确实有效,但表下面也有同名的页脚标签,因此(在本例中)有3个页眉

名字

姓氏

行动

因此,当我运行时,名字和姓氏都会加倍。我试图找到一种只获取页眉标签而不获取页脚标签的方法

页脚HTML如下所示:

<tr>
    <th id="headingData_0" data-dbname="F_FName" rowspan="1" colspan="1">First Name
    </th>
    <th id="headingData_1" data-dbname="F_LName" rowspan="1" colspan="1">Last Name
    </th>
    <th rowspan="1" colspan="1">Action</th>
</tr>

名字
姓
行动
因此,我试图找出一种方法,以便只查询tr role=“row”部分,从而获得这些标题,而不需要其他内容。在任何给定的时间,标题可能有两个以上的标题,所以它并不总是只有两个标题


任何帮助都会很好

将其添加到选择器的开头:

$('tr[role="row"] > th[id*="headingData_"]').each(function () {
    fieldNames += $(this).data("dbname") + '~';
    console.log(fieldNames);
});

旁注,ID必须是唯一的。@j08691是的,这是正确的,但我使用的jQuery插件正在填充您在上面看到的页眉和页脚的HTML代码。在这种情况下,我建议您不要使用该插件,因为它显然写得很糟糕。确实如此。谢谢你,乔!