Show div when radio button selected

前端 未结 5 664
花落未央
花落未央 2020-12-05 14:29

I am novice in javascript and jQuery. In my html have 2 radio buttons and one div. I want to show that div if I check the first radio-button but otherwise I want it to be hi

相关标签:
5条回答
  • 2020-12-05 14:30
    var switchData = $('#show-me');
    switchData.hide();
    $('input[type="radio"]').change(function(){ var inputData = $(this).attr("value");if(inputData == 'b') { switchData.show();}else{switchData.hide();}});
    

    JSFIDDLE

    0 讨论(0)
  • 2020-12-05 14:32
     $('input[type="radio"]').change(function(){
          if($("input[name='group']:checked")){
          $(div).show();
        }
      });
    
    0 讨论(0)
  • 2020-12-05 14:47
    $('input[name=test]').click(function () {
        if (this.id == "watch-me") {
            $("#show-me").show('slow');
        } else {
            $("#show-me").hide('slow');
        }
    });
    

    http://jsfiddle.net/2SsAk/2/

    0 讨论(0)
  • 2020-12-05 14:49

    I would handle it like so:

    $(document).ready(function() {
       $('input[type="radio"]').click(function() {
           if($(this).attr('id') == 'watch-me') {
                $('#show-me').show();           
           }
    
           else {
                $('#show-me').hide();   
           }
       });
    });
    
    0 讨论(0)
  • 2020-12-05 14:56

    Input elements should have value attributes. Add them and use this:

    $("input[name='test']").click(function () {
        $('#show-me').css('display', ($(this).val() === 'a') ? 'block':'none');
    });
    

    jsFiddle example

    0 讨论(0)
提交回复
热议问题