Jump to content
lucyman7654

Problema Javascript

Recommended Posts

Screenshot by Lightshot uite si id-urile.

problema e ca daca adaug continutul fisierului .js in pagina.html intre <script></script> merge.

cand fac import nu, imi da eroare.

Asta pentru c? probabil incluzi scriptul in head.. ?i se execut? de sus în jos la parsare.. iar DOM-ul nu a apucat s?-?i dea load complet.

Pentru a rezolva problema asta, te po?i folosi de jQuery, are o func?ie numit? „ready” care o atribui la document.

Dac? nu folose?ti jQuery, po?i scrie urm?torul cod:


document.addEventListener("readystatechange", function(e) {
if (document.readyState == "complete") {
//codul t?u
}
});

Link to comment
Share on other sites

  • Active Members

Alta e faza , tu trebuie sa bagi tot codul ala dupa body , de ce? pentru ca tu incluzandu-l in head, celelalte elemente vor fi incarcate dupa el , si de aia primesti eroarea aia cu property of null . Ori bagi codul ala la sfarsitul body , ori bagi acele 4 linii de la inceput cu document.getElementById(...) in

<script>

document.body.onload=function(){

primele 4 linii de cod

};

</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...