Update tabellenmanipulation
This commit is contained in:
@@ -25,13 +25,79 @@
|
||||
|
||||
<script>
|
||||
let table = document.getElementById("table");
|
||||
let tableBody = document.createElement("tableBody");
|
||||
let counter = document.getElementById("dimension");
|
||||
let colcount = 0;
|
||||
let rowcount = 0;
|
||||
let fieldval = "Feld";
|
||||
|
||||
function inscolumn() {
|
||||
colcount += 1;
|
||||
function updateDimension() {
|
||||
counter.innerHTML = "Dimension: " + rowcount + " x " + colcount;
|
||||
}
|
||||
|
||||
function insrow() {
|
||||
let row = document.createElement("tr");
|
||||
tableBody.appendChild(row);
|
||||
table.appendChild(tableBody);
|
||||
if(colcount != 0){
|
||||
for(x=0; x<colcount; x++){
|
||||
let firstChild = tableBody.children[rowcount];
|
||||
let cell = document.createElement("td");
|
||||
let text = document.createTextNode(fieldval);
|
||||
cell.appendChild(text);
|
||||
firstChild.appendChild(cell);
|
||||
}
|
||||
}
|
||||
rowcount++;
|
||||
updateDimension();
|
||||
}
|
||||
|
||||
function delrow(){
|
||||
if(rowcount < 1){
|
||||
alert("Es kann keine weitere Zeile entfernt werden.");
|
||||
} else {
|
||||
let firstChild = tableBody.children[0];
|
||||
tableBody.removeChild(firstChild);
|
||||
rowcount--;
|
||||
updateDimension();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function inscolumn(){
|
||||
if(rowcount==1){
|
||||
let firstChild = tableBody.children[0];
|
||||
let cell = document.createElement("td");
|
||||
let text = document.createTextNode(fieldval);
|
||||
cell.appendChild(text);
|
||||
firstChild.appendChild(cell);
|
||||
} else {
|
||||
for(i=0; i<rowcount; i++){
|
||||
let firstChild = tableBody.children[i];
|
||||
let cell = document.createElement("td");
|
||||
let text = document.createTextNode(fieldval);
|
||||
cell.appendChild(text);
|
||||
firstChild.appendChild(cell);
|
||||
}
|
||||
}
|
||||
colcount++;
|
||||
updateDimension();
|
||||
}
|
||||
|
||||
function delcolumn(){
|
||||
if(colcount < 1){
|
||||
alert("Es kann keine weitere Zeile entfernt werden.");
|
||||
} else {
|
||||
for(i=0; i < rowcount; i++){
|
||||
let firstChild = tableBody.children[i];
|
||||
firstChild.deleteCell(0);
|
||||
}
|
||||
colcount--;
|
||||
updateDimension();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
Reference in New Issue
Block a user