根据选择的显示/隐藏DIV,使用data-toggle ="buttons"按钮.输入单选按钮引导程序3 [英] Show/hide DIV based on selected with data-toggle="buttons" input radio button bootstrap 3

查看:165
本文介绍了根据选择的显示/隐藏DIV,使用data-toggle ="buttons"按钮.输入单选按钮引导程序3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里已经用Java脚本和Jquery检查了几乎所有可能的解决方案.但是无法找到解决方案.几乎所有的解决方案都可以使用"data-toggle ="buttons".但是我需要使用data-toggle ="buttons".

Have checked almost every possible solution with java script and Jquery here. But not able to find the solution for this. Almost every solution working with your "data-toggle="buttons". But I need with data-toggle="buttons".

这是我的代码:

    <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();
    });
});

此处引用此处

您可以在此处进行实时检查.已同时添加data-toggle ="buttons"和未添加data-toggle ="buttons"

you can check live here. Have added both with data-toggle="buttons" and with out data-toggle="buttons"

推荐答案

按如下所示更新您的jquery.

Update your jquery like below.

$(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();
});

});

演示

这篇关于根据选择的显示/隐藏DIV,使用data-toggle ="buttons"按钮.输入单选按钮引导程序3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆