[syntaxe] " = function()"
Bonjour, j'ai trouv� un script (servant � afficher un menu d�roulant) que je n'arrive pas vraiment � comprendre.
Il utilise la syntaxe :
variable = function() { code de la fonction }
ce qui n'a apparement pas le m�me effet que :
function nom(arguments) { code de la fonction }
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover = function() {
this.className+=" navOver";
}
node.onmouseout = function() {
this.className=this.className.replace(" navOver", "");
}
}
}
}
}
window.onload=startList; |
En effet, j'ai essay� d'�crire :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| function affiche() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover = function() {
this.className+=" navOver";
}
node.onmouseout = function() {
this.className=this.className.replace(" navOver", "");
}
}
}
}
}
window.onload=affiche(); |
Et je n'obtiens aucun r�sultat :
La fonction est bien 'visit�e' au chargement de la page mais apparement aucun �l�ment correspondant � l'ID "nav" n'est trouv�, alors qu'il l'est dans le premier cas...
Donc si vous pouviez m'�clairer sur ce point, je vous en serez tr�s reconnaissant ! (je n'ai rien trouv� sur cet usage de function() dans les tutoriels)