复制代码代码如下:
<html>
<head>
<script>
ฟังก์ชั่น createTable (แถวบรรทัด) {
this.rows = แถว;
this.lines = lines;
var body = document.getElementById ('body');
var table = document.createElement ('ตาราง'); // 创建ตาราง标签元素
table.setAttribute ('ชายแดน', '1');
// 给ตาราง标签添加其他属性
สำหรับ (var i = 0; i <this.rows; i ++) {
var lrow = document.createElement ('tr');
สำหรับ (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>
<body>
<div id = "body"> </div>
</body>
<script type = "text/javascript">
CreateTable (10,10);
</script>
</html>
第二种方法:
复制代码代码如下:
<script>
ฟังก์ชั่น createTable (แถวบรรทัด) {
this.rows = แถว;
this.lines = lines;
var body = document.getElementById ('body');
var table = document.createElement ('ตาราง');
table.setAttribute ('ชายแดน', 1);
สำหรับ (var i = 0; i <this.rows; i ++) {
var row = table.insertrow (i);
สำหรับ (var j = 0; j <this.lines; j ++) {
เซลล์ var = row.insertcell (j);
cells.innerhtml = i+','+j
-
-
Body.appendchild (ตาราง);
-
</script>