简体   繁体   English

JS:如何获取表中的肢体索引

[英]JS: how to get tbody index in table

I have a table with many tbodies inside. 我的桌子里面有很多东西。 For example: 例如:

<table id="tableId">
 <tbody id="tbodyId">
   <tr><td>1</td></tr>
 </tbody>
 <tbody>
   <tr><td>2</td></tr>
 </tbody>
 <tbody>
   <tr><td>3</td></tr>
 </tbody>
</table>

I need these tbody for grouping rows with span. 我需要这些tbody来对具有跨度的行进行分组。 How can I get certain tbody index in table via js? 如何通过js获取表中的某些tbody索引? I mean: 我的意思是:

var tbody=....;
var table=....;
var tbodyIndex=?

For example, for rows we can use rowIndex , but for tbodies? 例如,对于行,我们可以使用rowIndex ,但是对于tbodies?

EDIT Special edit for some users: 编辑一些用户特殊编辑:

var tbody=document.getElementById("tbodyId");
var table=document.getElementById("tableId");
var tbodyIndex=?

You could use: 您可以使用:

var tbody=document.getElementById("tbodyId");
var table=document.getElementById("tableId");
var tbodyIndex= [].slice.call(table.tBodies).indexOf(tbody); // [].slice.call() to convert HTML collection to array

-DEMO- -DEMO-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM