复制代码代码如下:
<html>
<Evista>
<script>
function createTable (filas, líneas) {
this.rows = filas;
this.lines = líneas;
var cuerpo = document.getElementById ('cuerpo');
var tabla = document.createElement ('tabla'); // 创建 Tabla 标签元素
Table.SetAttribute ('border', '1');
// 给 Tabla 标签添加其他属性
para (var i = 0; i <this.rows; i ++) {
var lrow = document.createElement ('tr');
para (var j = 0; j <this.lines; j ++) {
var textNode = document.createTextNode (i+','+j);
var lline = document.createElement ('td');
lline.appendChild (TextNode);
lrow.appendChild (lline);
}
Table.appendChild (lrow);
}
Body.appendChild (Tabla);
}
</script>
</ablo>
<Body>
<div id = "cuerpo"> </div>
</body>
<script type = "text/javaScript">
creatable (10,10);
</script>
</html>
第二种方法 :
复制代码代码如下:
<script>
function createTable (filas, líneas) {
this.rows = filas;
this.lines = líneas;
var cuerpo = document.getElementById ('cuerpo');
var tabla = document.createElement ('tabla');
Table.setAttribute ('border', 1);
para (var i = 0; i <this.rows; i ++) {
var fila = table.insertrow (i);
para (var j = 0; j <this.lines; j ++) {
VAR Cells = Row.insertcell (J);
Cells.innerhtml = i+','+j
}
}
Body.appendChild (Tabla);
}
</script>