javascript Table
来源:互联网 发布:淘宝企业店铺品牌授权 编辑:程序博客网 时间:2024/05/17 04:47
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Javascript Table </title>
<script type="text/javascript">
//方式1:用一般的DomAPI
function createTable1() {
var table = document.createElement("table");
table.setAttribute("border", "1px");
table.setAttribute("width", "100%");
var tbody = document.createElement("tbody");
table.appendChild(tbody);
//第一行
var tr1 = document.createElement("tr");
tbody.appendChild(tr1);
var td11 = document.createElement("td");
td11.appendChild(document.createTextNode("hello word cell 1,1"));
tr1.appendChild(td11);
var td12 = document.createElement("td");
td12.appendChild(document.createTextNode("hello word cell 1,2"));
tr1.appendChild(td12);
//第二行
var tr2 = document.createElement("tr");
tbody.appendChild(tr2);
var td21 = document.createElement("td");
td21.appendChild(document.createTextNode("hello word cell 2,1"));
tr2.appendChild(td21);
var td22 = document.createElement("td");
td22.appendChild(document.createTextNode("hello word cell 2,2"));
tr2.appendChild(td22);
return table;
}
//方式2:用Table自带的DomAPI
function createTable2() {
var table = document.createElement("table");
table.setAttribute("border", "1px");
table.setAttribute("width", "100%");
var tbody = document.createElement("tbody");
table.appendChild(tbody);
//第一行
var rowIndex = 0;
var colIndex = 0;
tbody.insertRow(rowIndex);
tbody.rows[rowIndex].insertCell(colIndex);
tbody.rows[rowIndex].cells[colIndex].appendChild(document.createTextNode("hello word cell 1,1")); colIndex++; //列索引递增
tbody.rows[rowIndex].insertCell(colIndex);
tbody.rows[rowIndex].cells[colIndex].appendChild(document.createTextNode("hello word cell 1,2")); colIndex++;
rowIndex++; //行索引递增
colIndex = 0;
//第二行
tbody.insertRow(rowIndex);
tbody.rows[rowIndex].insertCell(colIndex);
tbody.rows[rowIndex].cells[colIndex].appendChild(document.createTextNode("hello word cell 2,1")); colIndex++; //列索引递增
tbody.rows[rowIndex].insertCell(colIndex);
tbody.rows[rowIndex].cells[colIndex].appendChild(document.createTextNode("hello word cell 2,2")); colIndex++;
rowIndex++; //行索引递增
colIndex = 0;
return table;
}
function initTable() {
document.body.appendChild(document.createTextNode("1.用一般的DomAPI方式:"));
var table1 = createTable1();
document.body.appendChild(table1);
document.body.appendChild(document.createElement("br"));
document.body.appendChild(document.createTextNode("2.用Table自带API方式:"));
var table2 = createTable2();
document.body.appendChild(table2);
}
</script>
</head>
<body onload="initTable()">
<div id="show">
</div>
</body>
</html>
- TABLE JAVASCRIPT
- javascript Table
- javascript操作table
- JavaScript 实现table排序
- javascript 控制Table
- javascript动态增删Table
- JavaScript操作table
- javascript动态生成table
- javascript操作table
- javascript table delete row
- javascript insert table row
- JavaScript 编辑table
- JAVASCRIPT 操作HTML TABLE
- javascript table 添加行
- JavaScript Table排序
- JavaScript Table排序
- javascript Table排序
- JavaScript Table排序
- 获取IOS应用安装列表
- linux下C语言中的flock函数用法
- shell语法function
- NEFU 698 Post office 大概是dp?
- couchbase安装fedora18上的问题
- javascript Table
- 基础加强—06—类加载器
- shell语法while
- UESTC 1817——Complete Building the Houses 贪心
- Eclipse中的快捷键积累
- 下一代网络中的业务融合模式
- MySQL 可以用localhost 连接,但不能用IP连接的问题
- 简明Linux命令行笔记:ls
- NEFU 699 Lucky Boy 博弈?几何?