no save
Assistance
Achat
News

Forum | webmastering
btn1[.]a la valeur Null ou n'est pas un objet
Ebou_Ljabal, le dim. 27 juil. 2008 à 14:18:06
Bonjour,
J'ai besoin de vos consiels.
je débute en javascript. Je tente de faire marcher ce code :

var cpt_btn=0;
do{
btn1[cpt_btn]=document.createElement("img");
btn1[cpt_btn].src=btn[cpt_btn].src_out;
btn1[cpt_btn].className=btn[cpt_btn].class_name;
btn1[cpt_btn].alt=btn[cpt_btn].alt;
btn1[cpt_btn].onmouseover=function (cpt_btn){btn1[cpt_btn].src=btn[cpt_btn].src_over;}
btn1[cpt_btn].onmouseout=function (cpt_btn){btn1[cpt_btn].src=btn[cpt_btn].src_out;}
btn1[cpt_btn].onclick=function (cpt_btn){document.location=(btn[cpt_btn].cible);}
menu.appendChild(btn1[cpt_btn]);
cpt_btn++;
}while (cpt_btn<btn.length)

ce script ne marche ni dans FireFox ni dans IE. Dans IE je recois le message btn1[...] a lavaleur Null ou n'est pas un objet.
Par contre quand je le fait sans la boucle ça marche cad:

btn1[0]=document.createElement("img");
btn1[0].src=btn[0].src_out;
btn1[0].className=btn[0].class_name;
btn1[0].alt=btn[0].alt;
btn1[0].onmouseover=function (){btn1[0].src=btn[0].src_over;}
btn1[0].onmouseout=function (){btn1[0].src=btn[0].src_out;}
btn1[0].onclick=function (){document.location=(btn[0].cible);}
menu.appendChild(btn1[0]);

btn1[1]=document.createElement("img");
btn1[1].src=btn[1].src_out;
btn1[1].className=btn[1].class_name;
btn1[1].alt=btn[1].alt;
btn1[1].onmouseover=function (){btn1[1].src=btn[1].src_over;}
btn1[1].onmouseout=function (){btn1[1].src=btn[1].src_out;}
btn1[1].onclick=function (){document.location=(btn[1].cible);}
menu.appendChild(btn1[1]);

btn1[2]=document.createElement("img");
btn1[2].src=btn[2].src_out;
btn1[2].className=btn[2].class_name;
btn1[2].alt=btn[2].alt;
btn1[2].onmouseover=function (){btn1[2].src=btn[2].src_over;}
btn1[2].onmouseout=function (){btn1[2].src=btn[2].src_out;}
btn1[2].onclick=function (){document.location=(btn[2].cible);}
menu.appendChild(btn1[2]);
.......
.......

Je sais que le problème est dans le passage du compteur cpt_btn aux fonctions anonymes.
Je vous remercie d'avance.Configuration: Windows XP
Firefox 3.0.1


el_linwin
juil. 08
Suivant
REPONSES
el_linwin
juil. 08
Ebnou_Ljabal
juil. 08
Ebnou_Ljabal
juil. 08
el_linwin
juil. 08
Ebnou_Ljabal
juil. 08
el_linwin
juil. 08
Ebnou_Ljabal
juil. 08
el_linwin
juil. 08
Ebnou_Ljabal
juil. 08
Ebnou_Ljabal
juil. 08
Version Web
Réalisé par RedShift
no save