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

297
Views
Intentando ocultar un elemento de botón basado en una consulta de cadena en la URL usando javascript o JQuery. La URL tiene un "&" y dos "=" para dividir

Intentando ocultar un elemento de botón basado en una consulta de cadena en la URL usando javascript o JQuery

Si tengo una URL... por ejemplo:

 https://xxxxxx.com/xxxxxx.aspx?UserID=12345&type=ABCDE=true

El botón:

 <button class="smallButton"> </button>

¿Cómo oculto el botón si ABCDE = verdadero y lo muestro si no lo es? Leí otras publicaciones pero no parecían funcionar. Debido al "&" y los dos "=" en la cadena, es un poco diferente al ejemplo que he visto. Cualquier ayuda es apreciada. Gracias.

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

0

Puede obtener los parámetros de cadena de consulta utilizando URLSearchParams con .get

Luego, para obtener solo su valor, recorte la cadena antes de = y simplemente muestre u oculte el botón según la condición.

Puedes hacerlo así:

 let searchParams = new URLSearchParams("https://xxxxxx.com/xxxxxx.aspx?UserID=12345&type=ABCDE=true") // let searchParams = new URLSearchParams(window.location.search) uncomment if you want to use your current window location URL. if (searchParams.has('type')) { // check if the type exist in query string let param = searchParams.get('type') // get the param param = param.substr(param.indexOf('=') + 1, param.length) // trim the value to get true from "ABCDE=true" so in substr you're going to get the string from the char = position + 1 to the end of the string. if (param == 'true') { // check if the param is true $('.smallButton').show(); // show the button } else { $('.smallButton').hide(); // hide it } }
 .smallButton { display: none; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button class="smallButton"> SMALL BUTTON </button>

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!