HTML DOM Table cells 集合

2018-11-30 12:58 更新

Table cells 集合

Table 對(duì)象參考手冊(cè) Table 對(duì)象

定義和用法

cells 集合返回表格中所有 <td> 或 <th> 元素。

語(yǔ)法

tableObject.cells

Properties

屬性 描述
length 返回集合中 <td> 或 <th> 元素的數(shù)目。

方法

方法 描述
[name_or_index] 一個(gè)整數(shù),指定元素檢索位置(從0開始)
item(name_or_index) 返回集合中的指定索引的元素
namedItem(name) 返回集合中指定名稱索引的元素索引


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持 cells 集合


實(shí)例

實(shí)例

下面的例子使用 cells 來顯示出第一個(gè)單元格的內(nèi)容:

<html>
<head>
<script>
function displayResult()
{
alert(document.getElementById("myTable").rows[0].cells.length);
}
</script>
</head>
<body>

<table id="myTable" border="1">
 <tr>
   <td>cell 1</td>
   <td>cell 2</td>
 </tr>
 <tr>
   <td>cell 3</td>
   <td>cell 4</td>
 </tr>
</table>
<br>
<button type="button" onclick="displayResult()">Show number of cells</button>

</body>
</html>

嘗試一下 ?


實(shí)例

更多實(shí)例

彈出第一行的內(nèi)容

添加行

對(duì)齊表格行中的單元格內(nèi)容

表中的行的單元格內(nèi)容的垂直對(duì)齊

對(duì)齊單個(gè)單元格的內(nèi)容

單元格內(nèi)容的垂直對(duì)齊

改變表格單元格的內(nèi)容

合并單元格


Table 對(duì)象參考手冊(cè) Table 對(duì)象
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)