Afficher, cacher plusieurs divs
Salut,
Voilà, j'ai trouvé un script assez intéressant pour afficher et cacher des objets "div"
Le script de base se présente ainsi :
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
| <script language="javascript">
<!--
var state = 'hidden';
function showhide(layer_ref) {
if (state == 'visible') {
state = 'hidden';
}
else {
state = 'visible';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.visibility = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById && !document.all) {
tutu = document.getElementById(layer_ref);
tutu.style.visibility = state;
}
}
//-->
</script> |
Le html est :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<body>
<a href="#" onclick="showall('toto');">show all</a>
<a href="#" onclick="closeall('toto');">close all</a>
<a href="#" onclick="showhide('agent99');">click me</a>
<div id="agent99" style="position:absolute; top:103px; left:153px;
visibility:hidden;">
your stuff to show here
<a href="javascript://" onclick="showhide('agent99');">click me</a>
</div>
<br>
<br>
<a href="javascript://" onclick="showhide('toto');">click toto</a><br>
<div id="toto" style="visibility:hidden;">blux<a href="javascript://" onclick="showhide('toto');">click me</a>
</div>
</body> |
Toutefois, j'aimerais bien pouvoir ouvrir/fermer plusieurs "divs" à la fois.
J'ai donc tenté de créer 2 fonctions "showall" et "closeall" :
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 32 33 34 35 36 37 38 39
| function showall(layer_ref) {
if (state == 'visible') {
state = 'visible';
}
else {
state = 'visible';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.visibility = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById && !document.all) {
tutu = document.getElementById(layer_ref);
tutu.style.visibility = state;
}
}
function closeall(layer_ref) {
if (state == 'visible') {
state = 'hidden';
}
else {
state = 'hidden';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.visibility = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById && !document.all) {
tutu = document.getElementById(layer_ref);
tutu.style.visibility = state;
}
} |
Malheureusement, ça ne fonctionne pas trop bien.....
L'un d'entre vous aurait-il une idée ?
Merci beaucoup :D