Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > JavaScript
JavaScript Forum programmation JavaScript. Lire : Cours JavaScript, FAQ JavaScript, Toutes les FAQ JavaScript et Sources JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 21/02/2011, 12h15   #1
Invité de passage
 
Homme
Inscription : octobre 2006
Messages : 22
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : octobre 2006
Messages : 22
Points : 2
Points : 2
Par défaut Afficher/Masquer des div

Bonjour,

J'ai un petit soucis avec mon javascript.
J'essaye d'afficher/masquer un div mais ça ne fonctionne toujours pas alors que je suis sûr qu'il ne manque pas grand chose.

Voilà déjà le code javascript :

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
30
31
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
    alert('Layers : '+layers[i]);
 
}
 
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
  if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
  obj.visibility=v;
  }
    alert('showHideLayers : '+v);
 
}	
 
function onglet(p,n) {
	if(document.getElementById) {
		for(i=1;i<n+1;i++) {
			document.getElementById('tab['+i+']').className='tab_off';
			MM_showHideLayers('div'+i,'','hide');
			//alert('boucle : div'+i+' - tab['+i+']');
		}
        document.getElementById('tab['+p+']').className='tab_on';
		MM_showHideLayers('div'+p,'','show');
		alert('fin du if : div'+p+' - tab['+p+']');
    }
}

Et le code de ma page :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
<ul id="tabnav" >
	<li id="tab[1]" class="tab_on"><a href="#" onClick="javascript:onglet(1,2);">Description</a></li>
	<li id="tab[2]" class="tab_off"><a href="#" onClick="javascript:onglet(2,2);">Photos</a></li>
</ul>
 
<div id="div1" class="calque" style="position: absolute; visibility: visible; z-index: 1;">
<p>Test 1</p>
</div>
 
<div id="div2" class="calque" style="visibility: hidden; z-index: 2;">
<p>Test 2</p>
</div>

Si quelqu'un voit le petit bug !?

Le premier id tabNav fonctionne bien, mais ce n'est pas tout à fait le même principe, on change juste la class.
chris801 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/02/2011, 13h47   #2
Invité de passage
 
Homme
Inscription : octobre 2006
Messages : 22
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : octobre 2006
Messages : 22
Points : 2
Points : 2
Par défaut C'est bon

Ça fonctionne.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
 
function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
obj.visibility=v; }
}
J'ai mis à jour ces deux fonctions.
chris801 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h51.


 
 
 
 
Partenaires

Hébergement Web