jQuery radio button show div

前端 未结 4 708
余生分开走
余生分开走 2021-01-15 18:53

Hey guys, what function could I use to say, if this radio button is checked show this \'div\'. Thanks in advance.

4条回答
  •  北海茫月
    2021-01-15 19:33

    HTML

    Show Div

    jQuery

    $('#form-id').change(function() {
        if ($('#watch-me').attr('checked')) {
            $('#show-me').show();
        } else {
            $('#show-me').hide();
        }
    });
    

    You can see it in action here: http://jsfiddle.net/wmKGd/

    UPDATE 25.01.2013
    After Upgrading from jQuery Library 1.8.x to 1.9.x
    Please use instead of
    jQuery Library 1.8.x

    jQuery('#some-id').attr('checked') 
    

    jQuery Library 1.9.x

    jQuery('#some-id').prop('checked')
    

    You can see it with updated script in action here: http://jsfiddle.net/9XXRY/

提交回复
热议问题