La première méthode:
La copie de code est la suivante:
<html>
<adal>
<cript>
Fonction CreateTable (lignes, lignes) {
this.Rows = lignes;
this.lines = lignes;
var body = document.getElementById ('corps');
var table = document.CreateElement ('Table'); // Créer un élément de balise de table
Table.setAttribute («bordure», «1»);
// ajouter d'autres attributs à la balise de table
pour (var i = 0; i <this.Rows; i ++) {
var lrow = document.createElement ('tr');
pour (var j = 0; j <this.lines; j ++) {
var textNode = document.createTextNode (i + ',' + j);
var lline = document.createElement ('td');
lline.appendChild (textNode);
Lrow.ApendChild (Lline);
}
Table.ApendChild (lrow);
}
Body.ApendChild (tableau);
}
</cript>
</ head>
<body>
<div id = "body"> </ div>
</docy>
<script type = "text / javascript">
créatiable (10,10);
</cript>
</html>
La deuxième méthode:
La copie de code est la suivante:
<cript>
Fonction CreateTable (lignes, lignes) {
this.Rows = lignes;
this.lines = lignes;
var body = document.getElementById ('corps');
var table = document.CreateElement ('Table');
Table.setAttribute («bordure», 1);
pour (var i = 0; i <this.Rows; i ++) {
var row = table.insertrow (i);
pour (var j = 0; j <this.lines; j ++) {
var cellules = row.insertCell (j);
cells.innerhtml = i + ',' + j
}
}
Body.ApendChild (tableau);
}
</cript>
Avez-vous tous compris les deux méthodes ci-dessus? S'il existe une meilleure méthode, veuillez laisser un message pour l'expliquer et progresser ensemble.