Aide: problème de liens dans menu javascript - Programmation
TomsGuide.com : 700 000 inscrits répondent à toutes vos questions high-tech et informatique.
Pour obtenir de l'aide, inscrivez-vous gratuitement !
 




Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet : Aide: problème de liens dans menu javascript
 
Profil : IDNaute
Plus d'informations

Bonjour à tous,

Suite à mon autre topic, mes problèmes ont évolué. J'ai réussi à faire mon menu mais il reste un "petit détail": rien ne se passe lorsqu'on clique sur les liens du menu. Voici le code du menu:

Code :
  1. <style type="text/css">
  2. body{
  3.     font-family: sans-serif;
  4.     padding-left:5%;
  5.     padding-right:5%;
  6. }
  7. #logo{
  8.     font-size:2em;
  9.     border-bottom:1px dotted silver;
  10.     color:silver;
  11. }
  12. #myMenu{
  13.     float:left;
  14.     width:15%;
  15. }
  16. #content{
  17.     float:left;
  18.     width:100%;
  19.     font-size:0.8em
  20. }
  21. h3{
  22.     margin-top:0;
  23. }
  24. p{
  25. }
  26. #copyright{
  27.     clear:both;
  28.     border-top:1px solid silver;
  29.     margin-top:20px;
  30.     text-align:left;
  31.     padding-right:5px;
  32.     font-size:0.5em;
  33. }
  34. /* menu styles */
  35. li.myMenu0{
  36.     margin:0;
  37.     padding:0;
  38.     list-style : none;
  39. }
  40. a.myMenu0{
  41.     display:block;
  42.     position:relative;
  43.     background-color:white;
  44.     padding:3px;
  45.     text-decoration:none;
  46.     color:Navy;
  47.     border:1px solid blue;
  48.     margin-top:10px;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <div align="left">
  54.   <ul id="myMenu">
  55.     <li><a href="#">Menu </a>
  56.         <ul>
  57.           <!-- NOTE: No space between A tag and UL or IE will make space between the elements -->
  58.           <li><a href="http://virtuailes.iquebec.com">Accueil</a></li>
  59.           <li><a href="http://virtuailes.iquebec.com/avianews.php">News Aéronautiques</a></li>
  60.           <li><a href="http://virtuailes.iquebec.com/index2.php">News du site</a></li>
  61.           <li><a href="http://galerie.virtuailes.iquebec.com/">Galerie</a></li>
  62.           <li><a href="http://virtuailes.iquebec.com/connexion.php">Connexion</a></li>
  63.         </ul>
  64.     </li>
  65.     <li> <a href="#">Contenu</a>
  66.         <ul>
  67.           <li><a href="http://virtuailes.iquebec.com/script/engine.php">Recherche Interne</a></li>
  68.           <li><a href="http://virtuailes.iquebec.com/google.php">Recherche Google</a></li>
  69.           <li><a href="http://virtuailes.iquebec.com/dossiers.php">Dossiers</a></li>
  70.           <li><a href="http://virtuailes.iquebec.com/creations.php">Créations</a></li>
  71.           <li><a href="http://virtuailes.iquebec.com/fichiers.php">Téléchargements</a></li>
  72.           <li><a href="http://galerie.virtuailes.iquebec.com/">Galerie</a></li>
  73.           <li><a href="http://virtuailes.iquebec.com/privacypolicy.php">Copyright</a></li>
  74.         </ul>
  75.     </li>
  76.     <li> <a href="#">Communauté</a>
  77.         <ul>
  78.           <li><a href="http://client0.sigmachat.com/sc.pl?id%3d133784">Chat</a></li>
  79.           <li><a href="http://139968.aceboard.fr/index.php">Forum</a></li>
  80.           <li><a href="http://virtuailes.iquebec.com/liens.php">Liens</a></li>
  81.           <li><a href="http://virtuailes.iquebec.com/contact.php">Nous Contacter</a></li>
  82.           <li><a href="http://vote.weborama.fr/fcgi-bin/vote.fcgi?206750">Voter au Weborama</a></li>
  83.         </ul>
  84.     </li>
  85.     <li> <a href="#">Forum</a>
  86.         <ul>
  87.           <li><a href="http://139968.aceboard.fr/139968-867-0-Annonces.htm">Annonces</a></li>
  88.           <li><a href="http://139968.aceboard.fr/139968-1443-0-Bistrot.htm">Le Bistrot</a></li>
  89.           <li><a href="http://139968.aceboard.fr/139968-863-0-Sondages.htm">Sondages</a></li>
  90.           <li><a href="http://139968.aceboard.fr/139968-1686-0-Actualite.htm">Actualité</a></li>
  91.           <li><a href="http://139968.aceboard.fr/139968-1662-0-Dossiers.htm">Dossiers</a></li>
  92.           <li><a href="http://139968.aceboard.fr/139968-1436-0-rapport-avec-aviation.htm">En rapport avec l'aviation</a></li>
  93.           <li><a href="http://139968.aceboard.fr/139968-866-0-Site-VirtuAiles.htm">Le Site VirtuAiles</a></li>
  94.           <li><a href="http://139968.aceboard.fr/139968-1434-0-Questions-Techniques.htm">Questions Techniques</a></li>
  95.           <li><a href="http://139968.aceboard.fr/139968-864-0-Media-Photos-Video.htm">Média/Photos/Vidéo</a></li>
  96.           <li><a href="http://139968.aceboard.fr/139968-1444-0-connais-veux-vous-dire.htm">Je connais... et je veux vous dire</a></li>
  97.           <li><a href="http://139968.aceboard.fr/139968-1435-0-Questions-Generales.htm">Questions Générales</a></li>
  98.           <li><a href="http://139968.aceboard.fr/139968-1283-0-Liens-proposer.htm">Liens à proposer</a></li>
  99.           <li><a href="http://139968.aceboard.fr/139968-1457-0-Debats.htm">Débats</a></li>
  100.           <li><a href="http://139968.aceboard.fr/139968-1871-0-Reserve-Inscrits.htm">Réservé aux Inscrits</a></li>
  101.         </ul>
  102.     </li>
  103.     <li> <a href="#">Dossiers</a>
  104.         <ul>
  105.           <li><a href="http://virtuailes.iquebec.com/avro_arrow_introduction.php">L'Avro CF-105 Arrow</a></li>
  106.           <li><a href="http://virtuailes.iquebec.com/f35.php">Le F/A-35 JSF</a></li>
  107.           <li><a href="http://virtuailes.iquebec.com/sr71family.php">La famille Blackbird</a></li>
  108.           <li><a href="http://virtuailes.iquebec.com/constr.php">Le DHC-2 Beaver</a></li>
  109.           <li><a href="http://virtuailes.iquebec.com/constr.php">Le BA CSeries</a></li>
  110.           <li><a href="http://virtuailes.iquebec.com/constr.php">Le Convair B-58 Hustler</a></li>
  111.         </ul>
  112.     </li>
  113.     <li> <a href="#">Téléchargements</a>
  114.         <ul>
  115.           <li><a href="http://virtuailes.iquebec.com/telechargements_videos.php">Vidéos</a></li>
  116.           <li><a href="http://virtuailes.iquebec.com/telechargements_diaporammas.php">Diaporamas</a></li>
  117.           <li><a href="http://virtuailes.iquebec.com/telechargements_photos.php">Photos</a></li>
  118.           <li><a href="http://virtuailes.iquebec.com/telechargements_documents.php">Documents</a></li>
  119.           <li><a href="http://virtuailes.iquebec.com/telechargements_autres.php">Autres</a></li>
  120.         </ul>
  121.     </li>
  122.   </ul>
  123.   <script type="text/javascript">
  124. // <![CDATA[
  125. function loopElements(el,level){
  126.     for(var i=0;i<el.childNodes.length;i++){
  127.         //We only want LI nodes:
  128.         if(el.childNodes[i] && el.childNodes[i]["tagName"] && el.childNodes[i].tagName.toLowerCase() == "li" ){
  129.             //Ok we have the LI node - let's give it a className
  130.             el.childNodes[i].className = "myMenu"+level
  131.             //Let's look for the A and if it has child elements (another UL tag)
  132.             childs = el.childNodes[i].childNodes
  133.             for(var j=0;j<childs.length;j++){
  134.                 temp = childs[j]
  135.                 if(temp && temp["tagName"]){
  136.                     if(temp.tagName.toLowerCase() == "a" ){
  137.                         //We found the A tag - set class
  138.                         temp.className = "myMenu"+level
  139.                         //Adding click event
  140.                         temp.onclick=showHide;
  141.                     }else if(temp.tagName.toLowerCase() == "ul" ){
  142.                         //Hide sublevels
  143.                         temp.style.display = "none"
  144.                         //Set class
  145.                         temp.className= "myMenu"+level
  146.                         //Recursive - calling it self with the new found element
  147.                         //to go all the way through the three.
  148.                         loopElements(temp,level +1)
  149.                     }
  150.                 }
  151.             }
  152.         }
  153.     }
  154. }
  155. var menu = document.getElementById("myMenu" ) //Get menu div
  156. menu.className="myMenu"+0 //Set class to the top level
  157. loopElements(menu,0) //Call the function
  158. function showHide(){
  159.     //We have a A tag - need to go to the LI tag to check for UL tags:
  160.     el = this.parentNode
  161.     //Loop for UL tags:
  162.     for(var i=0;i<el.childNodes.length;i++){
  163.         temp = el.childNodes[i]
  164.         if(temp && temp["tagName"] && temp.tagName.toLowerCase() == "ul" ){
  165.             //Check status:
  166.             if(temp.style.display=="none" ){
  167.                 temp.style.display = ""
  168.             }else{
  169.                 temp.style.display = "none"
  170.             }
  171.         }
  172.     }
  173.     return false
  174. }
  175. // ]]>
  176. </script>
  177. </div>



Si quelqu'un peu m'aider...

Liens sponsorisés


Inscrivez-vous ou connectez-vous pour masquer ceci.

Profil : IDNaute
Plus d'informations

Moi je ne m y connais pas en html mais bien en dreamweaver
Si tu m envoies ton fichier par mail je pourrais l'examiner

Profil : IDNaute
Plus d'informations

C'est fait... si quelqu'un d'autre peut essayer.
Note: les autres liens fonctionnent, c'est seulement dans le menu que ca bogue.


Aller à :
 
  FORUM Infos-du-Net » Programmation » Aide: problème de liens dans menu javascript

Liens