在表中查找TD的位置 [英] Finding the location of a TD in a table
本文介绍了在表中查找TD的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以让我们说一个表,我想操纵一个特定的< td>
:
So let's say I have a table, and I want to manipulate a specific <td>
in it:
HTML:
<table>
<tr><td>1</td> <td>2</td></tr>
<tr><td>3</td> <td>4</td></tr>
<tr><td id="hi">5</td> <td>6</td></tr>
</table>
Javascript:
Javascript:
document.getElementsByTagName("table")[0].rows[2].cells[0];
这将帮助我REACH表中的特定单元格。
This will help me REACH a specific cell in a table.
我的问题是这样的:
说我有一个具体的< td>
表内:
Say I have a specific <td>
inside a table:
var td = document.getElementById("hi")
我想知道它在表中的位置,所以我可以使用 table.rows [x] .cells [y]
如何查看此位置?
I want to KNOW its location in the table, so I can be able to reach it using table.rows[x].cells[y]
How can I check this location?
推荐答案
我建议,你意味着你知道你想要找哪个特定的单元格,虽然目前未经测试:
I'd suggest, as you imply you know which specific cell you want to find, though currently untested:
var td = document.getElementById("hi"),
col = td.cellIndex,
row = td.parentNode.rowIndex;
这篇关于在表中查找TD的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文