[英]radio button show hide divs is not working properly
I have done some code for radio button group to show and hide the divs.我已经为单选按钮组做了一些代码来显示和隐藏 div。 but this code is not working properly.
但此代码无法正常工作。 could you please look into this.
你能看看这个吗? Thank you.
谢谢你。
<div class="col-md-7">
<div>
<h3 class="radio_heading">Radio Button Group</h3>
<form>
<label><input id="rdb1" type="radio" name="toggler" value="1" checked/>Book</label>
<label><input id="rdb2" type="radio" name="toggler" value="2" />Non-Book</label>
</form>
<div id="blk-1" class="toHide">
<form action="success1.html">
Name1:<input type="text" name="name">
<input type="submit" name="submit">
</form>
</div>
<div id="blk-2" class="toHide" style="display:none">
<form action="success1.html">
Name2:<input type="text" name="name">
<input type="submit" name="submit">
</form>
</div>
</div>
</div>
$(function() {
$("[name=toggler]").click(function(){
$('.toHide').hide();
$("#blk-"+$(this).val()).show('slow');
});
});
I copied and pasted your code, added the jQuery library, and it appears to work fine.我复制并粘贴了您的代码,添加了 jQuery 库,它似乎工作正常。
$(function() { $("[name=toggler]").click(function(){ $('.toHide').hide(); $("#blk-"+$(this).val()).show('slow'); }); });
<div class="col-md-7"> <div> <h3 class="radio_heading">Radio Button Group</h3> <form> <label><input id="rdb1" type="radio" name="toggler" value="1" checked/>Book</label> <label><input id="rdb2" type="radio" name="toggler" value="2" />Non-Book</label> </form> <div id="blk-1" class="toHide"> <form action="success1.html"> Name1:<input type="text" name="name"> <input type="submit" name="submit"> </form> </div> <div id="blk-2" class="toHide" style="display:none"> <form action="success1.html"> Name2:<input type="text" name="name"> <input type="submit" name="submit"> </form> </div> </div> </div> <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.