Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

425
Views
Escribí dos scripts js, ambos funcionan, pero el problema es que solo funcionará el que se encuentra en segundo lugar en el código.

Estoy tratando de desarrollar un sitio web de comercio electrónico por primera vez, pero aquí escribí dos guiones.

Como puede ver en las imágenes, funciona bien, pero solo el que se colocó en segundo lugar funcionará en el sitio web, en la primera imagen, el script desplegable funciona, en el segundo, funciona la función de desplazamiento.

 //show dropdowns// function myFunction(a) { a.parentNode.getElementsByClassName('dropdown-content')[0].classList.toggle("show"); } //click anywhere to hide dropdown// window.onclick = function(event) { if (!event.target.matches('.dropbtn')) { var dropdowns = document.getElementsByClassName("dropdown-content"); var i; for (i = 0; i < dropdowns.length; i++) { var openDropdown = dropdowns[i]; if (openDropdown.classList.contains('show')) { openDropdown.classList.remove('show'); } } } }; window.onscroll = function () { myFunction(); }; function myFunction() { if (document.documentElement.scrollTop > 50) { document.getElementById("tph").className = "scrolled"; } else { document.getElementById("tph").className = "header_top"; } }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intente cambiar el nombre de una de sus funciones para evitar sobrescribir.

JavaScript admite anular, no sobrecargar, lo que significa que si define dos funciones con el mismo nombre, la última definida anulará la versión definida anteriormente y cada vez que se realice una llamada a la función, se ejecutará la última definida.

 function myFunction(a) { a.parentNode.getElementsByClassName('dropdown-content')[0].classList.toggle("show"); } //click anywhere to hide dropdown// window.onclick = function(event) { if (!event.target.matches('.dropbtn')) { var dropdowns = document.getElementsByClassName("dropdown-content"); var i; for (i = 0; i < dropdowns.length; i++) { var openDropdown = dropdowns[i]; if (openDropdown.classList.contains('show')) { openDropdown.classList.remove('show'); } } } }; window.onscroll = function() { myFunction2(); }; function myFunction2() { if (document.documentElement.scrollTop > 50) { document.getElementById("tph").className = "scrolled"; } else { document.getElementById("tph").className = "header_top"; } }

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!