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

128
Views
haga clic o cambie el evento en la radio usando jquery

Tengo algunas radios en mi página, y quiero hacer algo cuando cambie la radio marcada, sin embargo, el código no funciona en IE:

 $('input:radio').change(...);

Y después de buscar en Google, la gente sugiere usar el clic en su lugar. Pero no funciona.

Este es el código de ejemplo:

 <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <script type="text/javascript"> $('document').ready( function(){ $('input:radio').click( function(){ alert('changed'); } ); } ); </script> </head> <body> <input type="radio" name="testGroup" id="test1" />test1<br/> <input type="radio" name="testGroup" id="test2" />test2<br/> <input type="radio" name="testGroup" id="test3" />test3</br> </body> </html>

Tampoco funciona en IE.

Entonces quiero saber que esta pasando?

También tengo miedo si se reactivará el evento de cambio si hago clic en una radio marcada.

ACTUALIZAR:

No puedo agregar comentarios, así que respondo aquí.

Uso IE8 y el enlace que Furqan me dio tampoco funciona en IE8. No se por que...

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Este código funcionó para mí:

 $(function(){ $('input:radio').change(function(){ alert('changed'); }); });

http://jsfiddle.net/3q29L/

over 4 years ago · Santiago Trujillo Report

0

Puede especificar el atributo de nombre de la siguiente manera:

 $( 'input[name="testGroup"]:radio' ).change(
over 4 years ago · Santiago Trujillo Report

0

Funciona para mí también, aquí hay una mejor solución:

demostración de violín

 <form id="myForm"> <input type="radio" name="radioName" value="1" />one<br /> <input type="radio" name="radioName" value="2" />two </form> <script> $('#myForm input[type=radio]').change(function() { alert(this.value); }); </script>

Debe asegurarse de haber inicializado jquery por encima de todas las demás funciones de importación y javascript. Porque $ es una función jquery . Incluso

 $(function(){ <code> });

no verificará jquery inicializado o no. Se asegurará de que <code> se ejecute solo después de que se hayan inicializado todos los javascripts.

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!