我正在尝试使用Bootstrap 4创建一个表单,在单击每个“按钮”时展开不同的元素. 它应该如何工作: 按钮(收音机):是/否— 如果单击“是”,则会展开包含复选框按钮的元素. div class="btn
它应该如何工作:
按钮(收音机):是/否—
如果单击“是”,则会展开包含复选框按钮的元素.
<div class="btn-group" data-toggle="buttons"> <label class="btn btn-primary active" data-toggle="collapse" href="#collapseExample" aria-expanded="false"> <input type="radio" name="options" id="option2" autocomplete="off"> Yes </label> <label class="btn btn-primary"> <input type="radio" name="options" id="option3" autocomplete="off"> No </label> </div> <!-- Expanded Buttons --> <div class="btn-group collapse" id="collapseExample" data-toggle="buttons"> <label class="btn btn-primary active"> <input type="checkbox" autocomplete="off"> Checkbox 2 </label> <label class="btn btn-primary"> <input type="checkbox" autocomplete="off"> Checkbox 3 </label> </div> <!-- / Expand Buttons -->
这是我的笔的a link.
如果你想只使用本机Bootstrap 4类(没有任何自定义css),那么这将是一种方法:<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <div> <button class="navbar-toggler pl-1" type="button" data-toggle="collapse" data-target="#collapseExample" aria-controls="collapseExample" aria-expanded="false" aria-label="Toggle navigation"> <div class="form-check"> <label class="btn btn-primary active" data-toggle="collapse" data-target="#collapseExample" href="#collapseExample" aria-expanded="false"> <input type="radio" name="options" id="option2" autocomplete="off"> Yes </label> </div> </button> <label class="btn btn-primary"> <input type="radio" name="options" id="option3" autocomplete="off"> No </label> <div class="collapse pl-4" id="collapseExample"> <!-- Expanded Buttons --> <div class="btn-group collapse" id="collapseExample"> <label class="btn btn-primary active"> <input type="checkbox" autocomplete="off"> Checkbox 2 </label> <label class="btn btn-primary"> <input type="checkbox" autocomplete="off"> Checkbox 3 </label> </div> <!-- / Expand Buttons --> </div> </div> <script src="http://img.558idc.com/uploadfile/allimg/210612/095ZT060-0.jpg" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="http://img.558idc.com/uploadfile/allimg/210612/095ZS915-2.jpg" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>