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

271
Views
Uso de un ancla para mostrar/ocultar divs en una aplicación asp mvc

En mi programa Asp MVC, puedo alternar un div con un botón. cshtml:

 <button onclick="ShowPubs()"> Click to show or hide</button>

JScipt:

función ShowPubs() {

 var x = document.getElementById("myPubs"); if (x.style.display === "none") { x.style.display = "block"; } else { x.style.display = "none"; }

}

y esto funciona bien,

sin embargo, al intentar usar enlaces como en este código: cshtnl:

 <div id="AboutShow" style="display:block"> Show the hidden piece <a href="#" onclick="ShowAbout();">Show &#9660;</a> </div> <div id="AboutHide" style="display:none"> Hide these details <a href="#" onclick="ShowAbout();">Hide &#9650;</a> A lot more stuff </div>

usando este JavaScript:

función MostrarSobre() {

 var x = document.getElementById("AboutShow"); var y = document.getElementsById("AbourHide"); if (x.style.display === "none") { x.style.display = "block"; y.style.display = "none"; } else { x.style.display = "none"; y.style.display = "b;pck"; } return false;

}

La URL de la página agrega el # a la URL y no sucede nada más, ¿qué estoy haciendo mal aquí, por favor?

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

0

De lo contrario, usa y.style.display="b;pck" que no es la forma correcta . debe ser block ;

Necesitas algo como esto .

 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> #myDIV { width: 100%; padding: 50px 0; text-align: center; background-color: lightblue; margin-top: 20px; } </style> </head> <body> <a href="#" onclick="myFunction()">Try it</a> <div id="myDIV"> This is my DIV element. </div> <script> function myFunction() { var x = document.getElementById("myDIV"); if (x.style.display === "none") { x.style.display = "block"; } else { x.style.display = "none"; } } </script> </body> </html>

Hazme saber si esto funciona para ti

about 4 years ago · Juan Pablo Isaza Report

0

  1. cambiar getElementsById a getElementById
  2. cambiar AbourHide a AboutHide
  3. cambiar b;pck a block

Código:

 function ShowAbout() { var x = document.getElementById("AboutShow"); var y = document.getElementById("AboutHide"); if (x.style.display === "none") { x.style.display = "block"; y.style.display = "none"; } else { x.style.display = "none"; y.style.display = "block"; } return false; }

resultado: ingrese la descripción de la imagen aquí

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!