jQuery toggle div with radio buttons

后端 未结 3 1960
闹比i
闹比i 2020-12-30 05:16

Simple html & jQuery


相关标签:
3条回答
  • 2020-12-30 05:26

    Heres what you want I think. To start I would make the first radio button selected and the first div visible. Then switching buttons would swap the divs

    $("input:radio").click(function(){        
       $('#blk-1').toggle(); 
        $('#blk-2').toggle(); 
    });
    
    0 讨论(0)
  • 2020-12-30 05:40
    <label><input id="rdb1" type="radio" name="toggler" value="1" />Money</label>
    <label><input id="rdb2" type="radio" name="toggler" value="2" />Interest</label>
    
    <div id="blk-1" class="toHide" style="display:none">
        money
    </div>
    <div id="blk-2" class="toHide" style="display:none">
        interest
    </div>
    
    $(function() {
        $("[name=toggler]").click(function(){
                $('.toHide').hide();
                $("#blk-"+$(this).val()).show('slow');
        });
     });
    

    as in http://www.jsfiddle.net/eKFrW/

    0 讨论(0)
  • 2020-12-30 05:44
    $("input:radio").click(function(){
        $("div").hide();
        var div = "#blk-"+$(this).val();
        $(div).show();
    });
    

    Online demo here: http://jsfiddle.net/yLJPC/

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