根据所选数据切换显示/隐藏DIV ="按钮"输入单选按钮bootstrap 3

时间:2014-07-29 02:22:14

标签: javascript css twitter-bootstrap hide show

在这里用java脚本和Jquery检查了几乎所有可能的解决方案。但是无法找到解决方案。几乎每个解决方案都使用“data-toggle =”按钮“。但我需要使用data-toggle =”按钮“。

这是我的代码:

    <div class="btn-group btn-toggle"  data-toggle="buttons">
    <label class="btn btn-default">
      <input type="radio" name="subscription-period" value="3mths" > 3 months
    </label>
    <label class="btn btn-default">
      <input type="radio" name="subscription-period" value="6mths" > 6 months
    </label>
        <label class="btn btn-default">
      <input type="radio" name="subscription-period" value="12mths" > 12 months
    </label>
  </div>
</nav>

<div class="prices" data-period="3mths">A 1</div>
<div class="prices" data-period="6mths">B 1</div>
<div class="prices" data-period="12mths">C 1</div>

<div class="prices" data-period="3mths">A 2</div>
<div class="prices" data-period="6mths">B 2</div>
<div class="prices" data-period="12mths">C 2</div>

<div class="prices" data-period="3mths">A 2</div>
<div class="prices" data-period="6mths">B 2</div>
<div class="prices" data-period="12mths">C 3</div>

JS:

$(document).ready(function() {
    $(".prices").hide();

    $("input[name$='subscription-period']").click(function() {
        var test = $(this).val();
        $(".prices").hide();
        $(".prices[data-period='" + test + "']").show();
    });
});

此处参考here

您可以查看直播here。添加了data-toggle =“buttons”和out-data-toggle =“buttons”

1 个答案:

答案 0 :(得分:0)

更新您的jquery,如下所示。

$(document).ready(function() {
$(".prices").hide();
$(".btn-default").click(function(){
  var test = $(this).find("input[name$='subscription-period']").val();
    $(".prices").hide();
    $(".prices[data-period='" + test + "']").show();
});

});

DEMO