0
Adding/Deleting table rows
I need to add table row dynamically using HTML and JavaScript.Here's my code
1 Respuesta
0
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> Table Rows</title>
</head>
<body>
<button onclick=" ">Add Row</button><br/><br/>
<table width= "4"
height="5" border="5" id="newTable">
<thead>
<tr>
<td colspan="7" align="center"> Հուլիս 2017</td>
</tr>
<tr>
<th>Կիրակի</th>
<th>Երկուշաբթի</th>
<th>Երեքշաբթի</th>
<th>Չորեքշաբթի</th>
<th>Հինգշաբթի</th>
<th>Ուրբաթ</th>
<th>Շաբաթ</th>
</thead>
<tbody>
</tr>
<tr>
<td> 1</td>
<td> 2</td>
<td> 3</td>
<td> 4</td>
<td> 5</td>
<td> 6</td>
<td> 7</td>
</tr>
</tbody>
</table>
</body>
<script>
function addRow(trCount,tdCount){
var str = '';
str += '<tr>';
for (var i = 0; i < trCount; i++){
str += '<tr>';
for(var j = 0; j< tdCount; j++){
str+='<td></td>';
}
str += '</tr>';
}
return str;
}
var defaultTable = createTable(4,5);
var table = document.getElementById('newTable');
table.innerHTML = defaultTable;
function row(tdCount){
var str = "";
str+='<tr>';
for(var j = 0; j< tdCount; j++){
str+='<td></td>';
}
str+='</tr>';
return str;
}
var newRow = row(5);
function add(){
defaultTable+=newRow;
table.innerHTML = defaultTable;
}
</script>
</html>