1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| <html>
<head>
<title>test create</title>
<script type="text/javascript"></script>
<script>
var container;
var nouveauSpan;
var nouvelInput;
var nouveauBouton;
var nouveauBr;
function creer(span){
if (span == 'a'){
container = document.getElementById("container");
nouveauSpan = document.createElement("span");
nouvelInput = document.createElement("input");
nouveauBr = document.createElement("br");
nouvelInput.value = 'bla';
nouveauBouton = document.createElement("input");
nouveauBouton.type = 'submit';
nouveauBouton.value = 'effacer';
nouveauBouton.setAttribute("onclick", effacer());
nouveauSpan.appendChild(nouvelInput);
nouveauSpan.appendChild(nouveauBouton);
nouveauSpan.appendChild(nouveauBr);
}
else{
container = document.getElementById("container");
nouveauSpan = document.createElement("span");
nouveauSpan.innerHTML = ' gol';
}
container.appendChild(nouveauSpan);
}
function detruire(){
container = document.getElementById("container");
//if (container.childNodes.length>0){
container.removeChild(container.firstChild);
//}
}
function effacer(){
alert ('bla')
}
</script>
</head>
<body onload="detruire()">
<a href="#" id="bla" onclick="creer('a')">creer un span bla</a>
<a href="#" onclick="creer('b')">creer un span gol</a>
<div id="container">
</div>
<a href="#" onclick="detruire()"> detruire un span </a>
</body>
</html> |