Problema adaugare evenimente cross-browser

Discutii si intrebari legate de scripturi si functii JavaScript, jQuery si Ajax, cod JavaScript in general.
patricia
Mesaje:82

Problema adaugare evenimente cross-browser

Daca este ceva in neregula cu sintaxa ce gresesc?
Am incercat acelasi cod dar cu adaugare evenimente in etichete html si a mers, deci banuiesc ca daca e ceva in neregula, greseala se afla la apelarea functiilor;

Cod: Selectaţi tot

<html>
<head>
<title>
recapitulare
</title>
<script type="text/javascript">
var stocare=document.getElementsByTagName('DIV');
                      function trecere1(){
                      stocare[2].style.display='block';
					  stocare[3].style.display='block';
					   stocare[4].style.display='block';
					   }
                   function trecere2(){
                       stocare[7].style.display='block';
					   stocare[8].style.display='block';
					   }					   
					   
                     function trecere3(){
                       stocare[11].style.display='block';
					   stocare[12].style.display='block';
					   stocare[13].style.display='block';
					   }					   
					   
					  function ascunde1(){
                      stocare[2].style.display='none';
					  stocare[3].style.display='none';
					   stocare[4].style.display='none';
					   } 
					   
					    function ascunde2(){
                       stocare[7].style.display='none';
					   stocare[8].style.display='none';
					   }					   
					   
					   function ascunde3(){
                       stocare[11].style.display='none';
					   stocare[12].style.display='none';
					   stocare[13].style.display='none';
					   }	
					   
stocare[0].onmouseover=trecere1;
stocare[5].onmouseover=trecere2;
stocare[9].onmouseover=trecere3;
stocare[0].onmouseover=ascunde1;
stocare[5].onmouseover=ascunde2;
stocare[9].onmouseover=ascunde3;				   
</script>
<style type="text/css">
#meniu1{
position:absolute;
top:1250px;
left:100px;
width:200px;
height:200px;
background-color:transparent;
border:1px none red;
}
#submeniu1{
position:absolute;
top:0px;
left:0px;
background-color:red;
width:200px;
height:50px;
border:1px solid white;
display:block;
}
#submeniu2{
position:absolute;
top:50px;
left:0px;
background-color:red;
width:200px;
height:50px;
border:1px solid white;
display:none;
}
#submeniu3{
position:absolute;
top:100px;
left:0px;
background-color:red;
width:200px;
height:50px;
border:1px solid white;
display:none;
}
#submeniu4{
position:absolute;
top:150px;
left:0px;
width:200px;
height:50px;
background-color:red;
border:1px solid white;
display:none;
}
#cadru{
position:absolute;
top:800px;
left:50px;
border:3px solid red;
width:300px;
height:250px;
background-color:white;
}
#meniu2{
position:absolute;
top:1250px;
left:300px;
width:200px;
height:150px;
background-color:transparent;
border:1px none red;
}
#meniu3{
position:absolute;
top:1250px;
left:500px;
width:200px;
height:150px;
background-color:transparent;
border:1px none red;
}
</style>
</head>
<body>
</form>
<div id="meniu1">
<div id="submeniu1">
</div>
<div id="submeniu2">
</div>
<div id="submeniu3">
</div>
<div id="submeniu4">
</div>
</div>
<div id="meniu2">
<div id="submeniu1">
</div>
<div id="submeniu2">
</div>
<div id="submeniu3">
</div>
</div>
<div id="meniu3">
<div id="submeniu1">
</div>
<div id="submeniu2">
</div>
<div id="submeniu3">
</div>
<div id="submeniu4">
</div>
</div>
</body>
</html>
- Este adevarat ca in cazul metodei cross browser , functia si apelarea ei trebuiesc adaugate intr-un script ce se afla in body, si nu in head?
Am incercat asa si acum merge;
Va multumesc pentru orice sfat,mentionez ca sunt incepatoare.

MarPlo Mesaje:4343
Daca scriptul JavaScript apeleaza direct elemente HTML din pagina, este indicat sa fie adaugat in Body, dupa acele tag-uri Html; chiar mai la sfarsit, inainte de tag-ul de inchidere </body>. Asta deoarece browser-ul executa codul JavaScript imediat ce s-a incarcat. Daca e adaugat in Head, la executarea lui nu va gasi elementele HTML din Body, care sunt incarcate dupa el.
Dar daca e adaugat la sfarsit, inainte de </body>, deja elementele HTML sunt incarcate.

Subiecte similare