jQuery 找到 TR->TH 值
jQuery finding TR->TH value(s)
嘿,我这里有以下 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 代码确实有效 但是 table 下面还有同名的页脚标签,所以(在这个例子中)有3 header秒;
名字
姓氏
动作
所以当我 运行 它使 名字 和 姓氏 都加倍。我正在尝试找到一种方法 仅获取 header 标签 而不是页脚标签。
页脚 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" 部分以获得那些 header 仅此而已。 header 在任何给定时间可能有 2 个以上的标题,因此它并不总是只有 2 个标题。
任何帮助都会很棒!
将其添加到选择器的开头:
$('tr[role="row"] > th[id*="headingData_"]').each(function () {
fieldNames += $(this).data("dbname") + '~';
console.log(fieldNames);
});
嘿,我这里有以下 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 代码确实有效 但是 table 下面还有同名的页脚标签,所以(在这个例子中)有3 header秒;
名字
姓氏
动作
所以当我 运行 它使 名字 和 姓氏 都加倍。我正在尝试找到一种方法 仅获取 header 标签 而不是页脚标签。
页脚 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" 部分以获得那些 header 仅此而已。 header 在任何给定时间可能有 2 个以上的标题,因此它并不总是只有 2 个标题。
任何帮助都会很棒!
将其添加到选择器的开头:
$('tr[role="row"] > th[id*="headingData_"]').each(function () {
fieldNames += $(this).data("dbname") + '~';
console.log(fieldNames);
});