简体   繁体   中英

when i click the open button a text box should appear in the page

when i click the active button a box should appear in the page , and when i click closed it should hide from page

<div class="btn-group btn-group-toggle" data-toggle="buttons">
    <label class="btn btn-secondary ">
        <input type="radio" name="options" id="option1" autocomplete="off" checked> Open
    </label>
    <label class="btn btn-secondary">
        <input type="radio" name="options" id="option2" autocomplete="off"> Closed
    </label>
</div>

Use change event of radio button

 $("input[name='options']").on('change',function(){ if($(this).attr('id') == 'option1'){ $('#myDiv').show(); }else{ $('#myDiv').hide(); } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div style="height:100px" id="myDiv">MY DIV WILL BE HERE</div> <body> <div class="btn-group btn-group-toggle" data-toggle="buttons"> <label class="btn btn-secondary "> <input type="radio" name="options" id="option1" autocomplete="off" checked> Open </label> <label class="btn btn-secondary"> <input type="radio" name="options" id="option2" autocomplete="off"> Closed </label> </div>

You can use a bootstrap modal and modal button to open a box on a button click. if you want to make a custom button then here is the code for in jquery.

$(document).ready(function()
{
$("button.active").on("click",function()
{
$(".page-box").toggle();
//page-box is the box container which you want to open 
})


});


is that what you want ?

 $(document).ready(function() { $('input[name=options]').change(function(e) { var isOpen = $(this).val() == "Open"; $('#box').toggle(isOpen); }); });
 #box { padding-top: 15px; }
 <div class="btn-group btn-group-toggle" data-toggle="buttons"> <label class="btn btn-secondary "> <input type="radio" name="options" value="Open" id="option1" autocomplete="off" checked> Open </label> <label class="btn btn-secondary"> <input type="radio" name="options" value="Closed" id="option2" autocomplete="off"> Closed </label> </div> <div id="box">More Info</div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM