Ich würde gerne wissen, wie mein div abhängig von der Zahl vom Benutzer geklont klonen. Wenn er 3 eingibt und auf "submit" drückt, klont das 3 div, wenn 42 div kloniert und so weiter. Jemand kann helfen?Clone ein div je nach der Anzahl der eingereichten
Für jetzt habe ich nur eine Schaltfläche, die mein div jedes Mal klonen, wenn ich es drücke.
Vielen Dank im Voraus.
function colorDiv() {
\t var selection = document.getElementById('color').value;
\t var div = document.getElementById('change');
\t
\t switch (selection) {
\t \t case "1":
\t \t div.style.backgroundColor = 'grey';
\t \t break;
\t \t case "2":
\t \t div.style.backgroundColor = 'yellow';
\t \t break;
\t \t case "3":
\t \t div.style.backgroundColor = 'blue';
\t \t break;
\t \t case "4":
\t \t div.style.backgroundColor = 'red';
\t \t break;
\t \t case "5":
\t \t div.style.backgroundColor = 'green';
\t \t break;
\t }
}
function multi() {
\t var item = document.getElementById("change");
\t var ligne = document.getElementById("br");
\t var dupli = item.cloneNode(true);
\t var dupliLig = ligne.cloneNode(true);
\t document.body.appendChild(dupli);
\t document.body.appendChild(dupliLig);
}
<div id="change" style="height:200px; width:200px"></div>
<br id="br">
<select id="color" onchange="colorDiv()">
\t <option value=1>Grey</option>
\t <option value=2>Yellow</option>
\t <option value=3>Blue</option>
\t <option value=4>Red</option>
\t <option value=5>Green</option>
</select>
<input type="text" name="">
<input type="submit" onclick= "multi()" >
verwenden, um eine 'for' Schleife – m87