【问题标题】:Toggle a <DIV> between Hide/Show using a RadioButton使用 RadioButton 在隐藏/显示之间切换 <DIV>
【发布时间】:2016-08-26 07:50:01
【问题描述】:

我想要一个带有“更多信息”链接下方的单选按钮的表单,并根据所选按钮显示该链接更多的相应信息。

这是我的代码。但它不起作用:-(

$(document).ready(function(){
  $("div").hide();
});

$(document).ready(function(){
  if($('input:radio[name="tarif"][value="jour"]').prop('checked', true)){
    $("button").click(function(){
        $(".jour").toggle();
    });
  } else if($('input:radio[name="tarif"][value="nuit"]').prop('checked', true)){
    $("button").click(function(){
        $(".nuit").toggle();
    });
  }
});
<INPUT type= "radio" name="tarif" value="jour"> tarif de jour
<INPUT type= "radio" name="tarif" value="nuit"> tarif de nuit
<a href=# class="info">More information</a>
<div class="jour">
  <p>
    qedaqteeteataeteteat
  </p>
</div>
<div class="nuit">
  <p>
    ZEFSZEFSGDHZEGSHGREZREGR
  </p>
</div>
<button>Toggle between hide() and show()</button>

拜托,你能帮帮我吗?

【问题讨论】:

标签: jquery html radio-button


【解决方案1】:

不清楚你想用那个按钮完成什么,但假设你只需要单选按钮来切换选择(根据用户选择显示特定的 div 或链接),这可能对你有用:

$(document).ready(function(){
    $("[name=tarif]").click(function() {
        $("div").hide(); // not very safe, you probably want to add a class to those divs
        $("."+$(this).val()).show();
   });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多