复制代码代码如下 :
<html>
<헤드>
<cript>
함수 createTable (행, 선) {
this.rows = 행;
this.lines = 선;
var body = document.getElementById ( 'body');
var table = document.createelement ( 'table'); // 创建 创建 표 标签元素
Table.SetAttribute ( 'Border', '1');
// 给 테이블 给
for (var i = 0; i <this.rows; i ++) {
var lrow = document.createElement ( 'tr');
for (var j = 0; j <this.lines; j ++) {
var textnode = document.creatextNode (i+','+j);
var lline = document.createElement ( 'td');
lline.appendChild (TextNode);
lrow.appendchild (lline);
}
테이블. AppendChild (lrow);
}
Body.appendChild (표);
}
</스크립트>
</head>
<body>
<div id = "body"> </div>
</body>
<script type = "text/javaScript">
CreateTable (10,10);
</스크립트>
</html>
第二种方法 :
复制代码代码如下 :
<cript>
함수 createTable (행, 선) {
this.rows = 행;
this.lines = 선;
var body = document.getElementById ( 'body');
var table = document.createelement ( 'table');
Table.SetAttribute ( 'Border', 1);
for (var i = 0; i <this.rows; i ++) {
var row = table.insertrow (i);
for (var j = 0; j <this.lines; j ++) {
var cells = row.insertcell (j);
cells.innerhtml = i+','+j
}
}
Body.appendChild (표);
}
</스크립트>