Méthode insertRow()de la table

Table 对象参考手册Objet Table

Définition et utilisation

La méthode insertRow() est utilisée pour insérer une nouvelle ligne à une position spécifiée dans un tableau.

Syntaxe

tableObject.insertRow(index)

Valeur Description
index

Spécifie la position à laquelle insérer la nouvelle ligne (en commençant à 0).



Prise en charge des navigateurs

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Tous les principaux navigateurs prennent en charge la méthode insertRow()


Exemple

Exemple

Insérer une nouvelle ligne à la première position dans le tableau :

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutoriel d'exemple(example.com)</title>
<script>
function displayResult(){
    var table=document.getElementById("myTable");
    var row=table.insertRow(0);
    var cell1=row.insertCell(0);
    var cell2=row.insertCell(1);
    cell1.innerHTML="New";
    cell2.innerHTML="New";
}
</script>
</head>
<body>

<table id="myTable" border="1">
    <tr>
        <td>cellule 1</td>
        <td>cellule 2</td>
    </tr>
    <tr>
        <td>cellule 3</td>
        <td>cellule 4</td>
    </tr>
</table>
<br>
<button type="button" onclick="displayResult()">Insérer une nouvelle ligne</button>

</body>
</html>

Essayez-le vous-même »


Table 对象参考手册Objet Table Autres extensions