javascript - Ajouter table rangée dans jQuery

Mots clés : javascriptjqueryhtml-tablejavascript

meilleur 5 Réponses javascript - Ajouter table rangée dans jQuery

vote vote

92

<table id="myTable">   <tbody>     <tr>...</tr>     <tr>...</tr>   </tbody> </table> 
<table id="myTable">   <tbody>     <tr>...</tr>     <tr>...</tr>   </tbody>   <tr>...</tr> </table> 
$('#myTable tr:last').after('<tr>...</tr><tr>...</tr>'); 
$('#myTable > tbody:last-child').append('<tr>...</tr><tr>...</tr>'); 
vote vote

88

$("#tableID").find('tbody')     .append($('<tr>')         .append($('<td>')             .append($('<img>')                 .attr('src', 'img.png')                 .text('Image cell')             )         )     ); 
vote vote

79

$('#myTable').append('<tr><td>my data</td><td>more data</td></tr>'); 
vote vote

69

<table>     <tbody>         <tr><td>Foo</td></tr>     </tbody>     <tfoot>         <tr><td>footer information</td></tr>     </tfoot> </table> 
$("#myTable > tbody").append("<tr><td>row content</td></tr>"); 
vote vote

50

tableObject.insertRow(index) 
<html>     <head>         <script type="text/javascript">         function displayResult()         {             document.getElementById("myTable").insertRow(-1).innerHTML = '<td>1</td><td>2</td>';         }         </script>     </head>      <body>                <table id="myTable" border="1">             <tr>                 <td>cell 1</td>                 <td>cell 2</td>             </tr>             <tr>                 <td>cell 3</td>                 <td>cell 4</td>             </tr>         </table>         <br />         <button type="button" onclick="displayResult()">Insert new row</button>                 </body> </html> 

Questions similaires