Dig*_*lMC 5 html css html5 twitter-bootstrap twitter-bootstrap-3
我正在使用Bootstrap 3,我想创建一个单选按钮组,根据所选的单选按钮显示/隐藏内容.我希望尽可能使用所有HTML和数据属性.
以下是我的代码:
<div id="parent">
<input type="radio" name="group1" value="1" data-parent="#parent" data-toggle="collapse" data-target="#div1" />
<input type="radio" name="group1" value="2" data-parent="#parent" data-toggle="collapse" data-target="#div2" />
<div class="panel-collapse collapse in" id="div1">Content</div>
<div class="panel-collapse collapse in" id="div2">Content</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这将显示/ hode目标DIV就好了,但我需要它来关闭#Parent DIV内的所有其他DIV.
我知道你可以用面板做到这一点,但我从来没有看到它用单选按钮完成,而且我非常接近.
有任何想法吗 ?
您可以组合面板和单选按钮.只需使用单选按钮作为切换按钮,然后使用它来控制面板.
演示 http://www.bootply.com/Fdjc8kQiER#
源代码
<input type="radio" name="group1" value="1" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
<input type="radio" name="group1" value="2" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
<input type="radio" name="group1" value="3" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
1. What is HTML?
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
<p>HTML stands for HyperText Markup Language. HTML is the main markup language for describing the structure of Web pages. <a href="http://www.tutorialrepublic.com/html-tutorial/" target="_blank">Learn more.</a></p>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
2. What is Bootstrap?
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
<p>Bootstrap is a powerful front-end framework for faster and easier web development. It is a collection of CSS and HTML conventions. <a href="http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/" target="_blank">Learn more.</a></p>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
3. What is CSS?
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
<p>CSS stands for Cascading Style Sheet. CSS allows you to specify various style properties for a given HTML element such as colors, backgrounds, fonts etc. <a href="http://www.tutorialrepublic.com/css-tutorial/" target="_blank">Learn more.</a></p>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
唯一不完美的是,由于某种原因,单选按钮在您选择时不会更新.你再也看不到所选的了.(不知道这是怎么发生的......带引导程序的东西?如果你知道如何解决,请评论,所以我可以编辑)
希望能帮助到你