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

177
Views
ir al enlace al hacer clic en el botón - jQuery

Tengo un script como el siguiente

 $('.button1').click(function() { document.location.href=$(this).attr('id'); });

el button1 tiene identificaciones únicas variables. al hacer clic, la página debe redirigir a la url " www.example.com/index.php?id=buttonid " pero ahora la página está redirigiendo solo a " button id ".

Quiero agregar la cadena " www.example.com/index.php?id= " antes de la URL actual. ¿Cómo puedo hacer esto posible?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

$('.button1').click(function() { window.location = "www.example.com/index.php?id=" + this.id; });

En primer lugar, usar window.location es mejor ya que, de acuerdo con la especificación document.location , el valor era de solo lectura y podría causarle dolores de cabeza en navegadores más antiguos/diferentes. Consulte las notas en la página MDC DOM document.location

Y para el segundo, usar el método attr jQuery para obtener la identificación es una mala práctica, debe usar el acceso DOM nativo directo this.id ya que el valor asignado a this es un elemento DOM normal.

over 4 years ago · Santiago Trujillo Report

0

Necesitas especificar el dominio:

 $('.button1').click(function() { window.location = 'www.example.com/index.php?id=' + this.id; });
over 4 years ago · Santiago Trujillo Report

0

$('.button1').click(function() { document.location.href='/index.php?id=' + $(this).attr('id'); });
over 4 years ago · Santiago Trujillo 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!