js添加表格

caption:保存着对<caption>元素(如果有)的指针

tBodies:是一个<tbody>元素的HTMLCollection.

tFoot:保存着对<tfoot>元素的指针

tHead:保存着对<thead>元素的指针

rows:是一个表格所有行的HTMLCollection

createTHead():创建<thead>元素,将其放到表格中,返回引用

createTFoot():创建<tfoot>元素, 将其放在表格中,返回引用

createCaption();创建<caption>元素,将其放到表格中,返回引用

deleteTHead:删除<thead>元素

deleteTFoot:删除<tfoot>元素

delectCaption:删除<caption>元素

deleteRow(pos):删除指定位置的行

insertRow(pos):向rows集合中的指定位置插入一行

为<tbody>元素添加的寿星和方法如下

rows:保存<tbody>元素中行的HTMLCollection.

deleteRow(pos):删除指定位置的行

insertRohew(pos):向rows集合中的指定位置插入一行,返回对新插入行的引用。

为<tr>元素添加的属性和方法如下

cells:保存着<tr>元素中单元格的HTMLCollection.

deleteCell(pos):删除指定位置的单元格。

insertCell(pos):向cells集合中的指定位置插入一个单元格,返回对新插入单元格的引用

示例

var table = document.createElement("table");

table.border = 1;

table.width = "100%";

var tbody = document.createElement("tbody");

table.appendChild(tbody);

//创建第一行

tbody.insertRow(0);

tbody.rows[0].insertCell(0);

tbody.rows[0].cells[0].appendChild(document.createTextNode("Cell 1,1"));

tbody.rows[0].insertCell(1);

tbody.rows[0].cells[1].appendChild(document.createTextNode("Cell2,1"));

猜你喜欢

转载自www.cnblogs.com/msg001/p/9280565.html