Anzeigen oder ausblenden von div-oder Formular-element mit jquery?

Ich versuche zu zeigen, oder verstecken fieldset basierend auf der Antwort ausgewählt, die auf JA/NEIN-Optionsfeld. Ich habe mehrere Formular-Elemente werden ein-oder ausgeblendet, basierend auf Ihren entsprechenden JA/NEIN-Optionsfeld. Aber der code ist nicht für mich arbeiten. Könnte mir jemand helfen um dieses problem zu beheben?

<!-- My Form Element  -->

<form>
<fieldset id="question">
  <legend>This is my question</legend>
  <label for="answerYes">Yes</label>
  <input name="answer" class="myradio" type="radio" value="1" />
  <label for="answerNo">No</label>
  <input name="answer" class="myradio" type="radio" value="0" />
</fieldset>

<fieldset class="subQuestion">
  <legend>This is my question</legend>
  <label for="answerYes">Yes</label>
  <input name="answer" class="subradio" type="radio" value="1" />
  <label for="answerNo">No</label>
  <input name="answer" class="subradio" type="radio" value="0" />
</fieldset>

</form>


//Jquery to show or hide subQuestion

$(document).ready(function(){
  //do your checks of the radio buttons here and show/hide what you want to
  $(".subQuestion").hide();

  $(document).on('click', '.myradio' , function() {
         if ($(this.value).length > 0){ 
            $(".subQuestion").show();           
         }
         else {
            $(".subQuestion").hide();           
         }       
    })

});

InformationsquelleAutor MahiloDai | 2013-09-13

Schreibe einen Kommentar