Bonjour,
voici un code html utilisant la technique dom et javascript pour ajouter deux input et deux boutons;
le problème c'est que l'éxecution est bon sur FF mais pas sur IE
tous les bouttons ne marchent pas sauf le premier bouttons
voici le code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Document sans nom</title>
</head>
<script language="javascript">
var count = 1;
function delete_one_ligne ()
{
//list_row = document.getElementById('oo_nom_1');
alert(count);
count--;
list_row = document.getElementsByTagName('TR')[count];
alert(list_row.parentNode);
list_row.parentNode.removeChild(list_row);
}
function one_more_ligne () {
count++;
var tr = document.createElement("TR");
var td_1 = document.createElement("TD");
var td_2 = document.createElement("TD");
var td_3 = document.createElement("TD");
var td_4 = document.createElement("TD");
var inp1 = document.createElement("INPUT");
var inp2 = document.createElement("INPUT");
var bt1 = document.createElement("input");
//var txtbt1= document.createTextNode("Ajouter");
var bt2 = document.createElement("input");
inp1.name="oo_nom"; inp2.name="oo_valeur";
inp1.type="text"; inp2.type="text";
inp1.id="oo_nom_"+count; inp2.id="oo_valeur_"+count;
bt1.name = "oo_bt1_id" ; bt2.name = "oo_bt2_id" ;
bt1.id = "oo_bt1_id"+count; bt2.id = "oo_bt2_id"+count;
bt1.value="Ajouter"; bt2.value = "Supprimer";
bt1.type="button"; bt2.type="button";
bt1.setAttribute("onclick" , "one_more_ligne ();"); bt2.setAttribute("onclick", "delete_one_ligne ();");
td_1.appendChild(inp1);
td_2.appendChild(inp2);
td_3.appendChild(bt1);
//td_3.appendChild(txtbt1);
td_4.appendChild(bt2);
tr.appendChild(td_1);
tr.appendChild(td_2);
tr.appendChild(td_3);
tr.appendChild(td_4);
//elm = document.getElementById("table_1");
//elm = document.getElementById("ddd");
//elm = document.getElementsByTagName('p')[0];
//elm.appendChild(tr);
byId("table_1").getElementsByTagName('tbody')[0].appendChild(tr);
}
function byId(elmId){
var elm = document.getElementById(elmId);
if(elm==null)
elm = document.getElementsByName(elmId)[0];
alert(elm.innerHTML);
return elm;
}
</script>
<body>
<table id="table_1" name="table_1" border="1">
<tbody>
<tr>
<td><input type="text" id="oo_nom_1" name="oo_nom"/></td>
<td><input type="text" id="oo_valeur_1" name="oo_valeur"/></td>
<td><input type="button" id="oo_bt1_id" name="oo_bt1_name" value="Ajouter" onClick="one_more_ligne();" /></td>
<td><input type="button" id="oo_bt2_id" name="oo_bt2_name" value="Supprimer" onClick="delete_one_ligne();" /></td>
</tr>
</tbody>
</table>
</body>
</html>
Configuration: Windows Vista
Internet Explorer 7.0