复制代码代码如下:
<html>
<head>
<Cript>
função createTable (linhas, linhas) {
this.rows = linhas;
this.Lines = lines;
var corpo = document.getElementById ('corpo');
var tabela = document.createElement ('tabela'); // tabela 标签元素
Tabela.setAtAttribute ('borda', '1');
// Tabela 标签添加其他属性
for (var i = 0; i <this.rows; i ++) {
var lrow = document.createElement ('tr');
for (var j = 0; j <this.Lines; j ++) {
var textNode = document.createTextNode (i+','+j);
var lline = document.createElement ('td');
lLine.AppendChild (TextNode);
LROW.APPENDCHILD (LLINE);
}
Tabela.AppendChild (LROW);
}
Body.appendChild (tabela);
}
</script>
</head>
<Body>
<div id = "corpo"> </div>
</body>
<script type = "text/javascript">
createTable (10,10);
</script>
</html>
第二种方法
复制代码代码如下:
<Cript>
função createTable (linhas, linhas) {
this.rows = linhas;
this.Lines = lines;
var corpo = document.getElementById ('corpo');
var tabela = document.createElement ('tabela');
Tabela.setAtAttribute ('Border', 1);
for (var i = 0; i <this.rows; i ++) {
var row = tabela.insertrow (i);
for (var j = 0; j <this.Lines; j ++) {
var células = row.insertCell (j);
Cells.innerhtml = i+','+j
}
}
Body.appendChild (tabela);
}
</script>