Bonsoir à tous,
Je souhaite construire un menu horizontal sauf que j'ai un soucis avec la méthode write de la classe document.
En fait, chaque fois que je clique sur un choix de menu la méthode write() m'affiche le sous-menu dans une autre page, chose qu'est tout à fais normal car l'instruction document.write() recharge une nouvelle page du coup, ça m'affiche le sous-menu dans une nouvelle page et non pas dans la page souhaitée.
Je vous invite a tester mon code.
Merci d'avance.
<HTML>
<HEAD>
<TITLE> Menu horizontal </TITLE>
<SCRIPT language='JavaScript'>
function selectionner(obj){
obj.style.backgroundColor="#660066";
}
function deselectionner(obj){
obj.style.backgroundColor="blue";
}
var content="";
function afficherMenu(obj,parGauche,parHaut,indice){
var i;
var n=3;
content="<TABLE cellspacing=1 width=100px style='position:absolute;left:"+parGauche+";top:"+parHaut+"'>";
for(i=1;i<=n;i++)
content+='<TR><TD style="height:5px; text-align:center;background-color:gray;" >Sous-Menu'+indice+'-'+i+'</TD></TR>';
content+='<TABLE>';
document.write(content);
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
var i;
var n=6;
var gauche=10,haut=35;
document.write("<TABLE id='topdeck' cellspacing=1 width=600px>");
document.write("<TR>");
for(i=1;i<=n;i++){
if(i>1) gauche+=100;
document.write('<TD style="height:5px; text-align:center;background-color:blue;" onmouseover="selectionner(this)" onmouseout="deselectionner(this)" onclick="afficherMenu(this,'+gauche+','+haut+','+i+')">choix'+i+'</TD>');
}
document.write("</TR>");
document.write("</TABLE>");
</SCRIPT>
</BODY>
</HTML>