Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/03/2016, 13:01
Avatar de ceaped
ceaped
 
Fecha de Ingreso: febrero-2004
Mensajes: 2.185
Antigüedad: 20 años, 2 meses
Puntos: 9
Pregunta Quiz de preguntas que valide cual esta buena

Buenas tardes
Trato de hacer un quiz con varias preguntas que al seleccionar alguna opción y darle al botón respuesta me diga si la seleccionada esta buena y me de una pequeña respuesta si esta bien o mal.

Hasta ahora tengo esto:

Código Javascript:
Ver original
  1. $(document).ready(function(){
  2.     $('#respuesta').click(function() {
  3.         $("input[type='radio']:checked").each(function() {
  4.             if($("input[type='radio']:checked").val() == "Correct"){
  5.                 var id_val = $(this).attr("id");
  6.                 $("label[for='" + id_val + "']").css("background-color", "green");
  7.                
  8.             }else{
  9.                 var id_val = $(this).attr("id");
  10.                         $("label[for='" + id_val + "']").css("background-color", "red");
  11.             }
  12.         });
  13.     });
  14. });

Código HTML:
Ver original
  1.     <legend>Pregunta 1</legend>
  2.     <input type="radio" name="q1" id="1" onclick="checkthis('Incorrect');" /><label for="1">Pregunta 1</label>
  3.     <input type="radio" name="q1" id="2" onclick="checkthis('Incorrect');" /><label for="2">Pregunta 2</label>
  4.     <input type="radio" name="q1" id="3" onclick="checkthis('Incorrect');" /><label for="3">Pregunta 3</label>
  5.     <input type="radio" name="q1" id="4" onclick="checkthis('Correct');"   /><label for="4">Pregunta 4</label>
  6. <div id="here"></div>
  7.  
  8. <button id="respuesta">Respuesta</button>

Lo que deseo es generar varias preguntas.

Gracias por su ayuda
__________________
Diseñador Gráfico publicitario