0

我正在尝试做一个简单的隐藏/显示效果,具体取决于选中的单选按钮。它工作不正常,我不知道为什么。我希望在用户单击“Oui”时隐藏表格(#reprint_ouiSHOW......如果选择“Non”则隐藏。

这是我的 JS 代码:

$(document).ready(function(){

$("input[name$='reprint_group']").click(function(){

var radio_value = $(this).val();

if(radio_value=='Oui') {
    $("#reprint_oui").show("slow");
}
else if(radio_value=='Non') {
   $("#reprint_oui").show("slow");
   }
  });

$("#reprint_oui").hide();

});​

这是我的 HTML:

<h2>Fiche technique de production</h2>
      <table width="100%" border="0">
          <tr>
            <td width="80%">Avons-nous par le passé produit des affiches que vous vous apprêtez à commander?</td>
            <td width="20%"><label for="oui_reprint">Oui</label>
            <input name="reprint_group" type="radio" id="oui_reprint" value="Oui">
            <label for="non_newprint">Non</label>
            <input type="radio" name="reprint_group" id="non_newprint" value="Non"></td>
        </tr>
      </table>
      <table width="100%" border="0" id="reprint_oui">
        <tr>
          <td width="80%">S'agit-il d'une réimpression sans changement?</td>
          <td width="20%"><label for="oui_reprint">Oui</label>
            <input type="radio" name="reprint_sans_changement" id="oui_reprint" value="Oui">
            <label for="non_newprint">Non</label>
            <input type="radio" name="reprint_sans_changement" id="non_newprint" value="Non"></td>
        </tr>
      </table>

这是我的小提琴

谢谢

4

2 回答 2

1

show当单选值为 时,您实际上是在ing 表Non。改为hide()

if (radio_value == 'Oui') {
  $("#reprint_oui").show("slow");
} else if(radio_value == 'Non') {
  $("#reprint_oui").hide("slow"); // you have show() here
}

演示

于 2012-09-04T20:22:57.723 回答
0

if-else 的结果都显示了 reprint_oui 元素。

“非”时隐藏元素

http://jsfiddle.net/25KkU/1/

还要确保在 javascript 中进行比较时使用三重“=”:

if(a===b)
{}
于 2012-09-04T20:23:24.137 回答