2

以下表格:

    <form action="x.php" method="get" id="myForm">Subscribe:
<div id="radioButtonsWithAdds">
    <input type="radio" name="group1" value="one">One month 2,99$  
    <input type="radio" name="group1" value="two"> Two months   5,98$</div><br>
    <input type="checkbox" name="option1" value="withAdds" checked>  with adds
    <img src="next.png" border="0" alt="enviar" onclick="document.getElementById('myForm').submit();"> 
    </form>

是订阅的第一部分。在这里,用户可以选择一个月或两个月的订阅。

如果用户同意接收添加,勾选复选框,就可以了,他/她可以点击下一步按钮就可以了。

但是,如果用户取消选中“添加”复选框,则会在#radioButtonsWithAdds 的位置显示一个div,其中包含另一组价格不同的单选按钮。

如何在不点击任何提交按钮的情况下检测到复选框 ish?

4

5 回答 5

15
$('#yourcheckbox').change(function() {

   if ( ! this.checked) {
       // It is not checked, show your div...

   }

});
于 2011-01-27T12:20:09.003 回答
2

你也可以这样做:

$('input[name=subscribe]').change(function() {
   if ($(this).is(':checked')) {
     // the user selected the checkbox
   } else {
     // the user de-selected the checkbox
   }
});
于 2012-11-09T16:43:01.270 回答
1

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta name="generator" content="test"/>
    <title></title>
  </head>
  <body>
    <form action="x.php" method="get" id="myForm" name="myForm">
      Subscribe:
      <div id="radioButtonsWithOutAdds" style="display:none;">
        <input type="radio" name="group1" value="one">One month 1,99$
        <input type="radio" name="group1" value="two"> Two months 2,98$
      </div>
      <div id="radioButtonsWithAdds">
        <input type="radio" name="group1" value="one">One month 2,99$
        <input type="radio" name="group1" value="two"> Two months 5,98$
      </div><br>
      <input type="checkbox" name="option1" value="withAdds" checked> with adds
      <img src="next.png" border="0" alt="enviar" onclick=
      "document.getElementById('myForm').submit();">
    </form>
  </body>
</html>

JS

$(document).ready(function(){
    $("#myForm > input[type='checkbox']").click(function(){
        if(!$(this).is(':checked'))
        {
            $("#radioButtonsWithOutAdds").show();
            $("#radioButtonsWithAdds").hide();
        }
        else
        {
            $("#radioButtonsWithOutAdds").hide();
            $("#radioButtonsWithAdds").show();
        }
    })
})

这是一个简单的例子:http: //jsfiddle.net/efhHF/2/

于 2011-01-27T12:24:18.727 回答
0

您需要绑定一个事件侦听器并检查那里的状态。

$('#radioButtonsWithAdds').find('input:checkbox').bind('change', function() {
    if(this.checked) {
    }
    else {
         // the user unchecked the checkbox!
    }
});
于 2011-01-27T12:21:47.137 回答
0

尝试使用这个

          <TD width=550 align=left> 
                <input type="checkbox" name="adesao" value="sim" id="parte1" onClick="mostra()" /> Sim   
                <div id="sumula" style="display:none"> 
                    <input type="radio" name="conteudo_sumula" value="1" /> <small><i>1x</i></small> 
                    <input type="radio" name="conteudo_sumula" value="2" /> <small><i>2x</i></small> 
                    <input type="radio" name="conteudo_sumula" value="3" /> <small><i>3x</i></small> 
                </div> 
          </TD>

这里是 JS 函数

function mostra(){
    if (document.getElementById("sumula").style.display != "none"){
        document.getElementById("sumula").style.display = "none";
    }else{
        document.getElementById("sumula").style.display = "block";
    }
}
于 2011-01-27T12:22:56.373 回答