Comparaison de NodeList sous différents navigateurs
Salut,
Je cherche plus une explication qu'une solution. Alors si vous l'avez, je vous en remercie grandement par avance.
Sauriez-vous pourquoi une simple comparaison de deux listes de nœuds identiques sous Opera et Safari retourne "faux", alors que sous Firefox et internet explorer elle retourne "vrai".
Illustration :
Code:
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
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<title>comparer des listes de noeuds</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
* {margin:0;padding:0;color:#333;}
body {padding:80px; background:#000;}
form {margin:0 0 20px 0;padding:10px;width:260px;background:#333;}
</style>
</head>
<body>
<form id="f" method="post" action="perdu.html">
<p><input id="c1" type="checkbox" name="c" value="1" /></p>
<p><input id="c2" type="checkbox" name="c" value="2" /></p>
<p><input id="c3" type="checkbox" name="c" value="3" /></p>
</form>
<script type="text/javascript">
<!--
var ns1 = document.getElementsByTagName("input");
var ns2 = document.getElementsByTagName("input");
alert(ns1===ns2);
for(var i=0,imax=ns1.length;i<imax;i++){
alert(ns1[i]===ns2[i]);
}
//-->
</script>
</body>
</html> |
C'est désespérant...