close

在Html中,  table是由<table>這個tag所定義 , 

A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag).

在Javascript中 , 我們可以藉由cells來取得table中所有的td (or th)的element.

(The cells collection returns a collection of all <td> or <th> elements in a table.)

<html>
<head>
<script>
function displayResult()
{

var tableElement = document.getElementById("myTable");

alert(tableElement.cell[0] , tableElement.cell[1] , tableElement.cell[2] , tableElement.cell[3])

}
</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>



ref : http://www.w3schools.com/html/html_tables.asp

ref : http://www.w3schools.com/jsref/coll_table_cells.asp


arrow
arrow
    全站熱搜

    JerryCheng 發表在 痞客邦 留言(0) 人氣()