复制代码代码如下:
<html>
<голова>
<Скрипт>
Функция создать (ряды, строки) {
this.row = rows;
this.lines = 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.createTextNode (i+','+j);
var lline = document.createElement ('td');
lline.appendchild (TextNode);
lrow.appendchild (lline);
}
Table.appendchild (lrow);
}
Body.appendchild (таблица);
}
</script>
</head>
<тело>
<div id = "body"> </div>
</body>
<script type = "text/javascript">
создается (10,10);
</script>
</html>
第二种方法 :
复制代码代码如下:
<Скрипт>
Функция создать (ряды, строки) {
this.row = rows;
this.lines = 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 (таблица);
}
</script>