Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery hide show not work in单选按钮_Jquery_Radio Button - Fatal编程技术网

jquery hide show not work in单选按钮

jquery hide show not work in单选按钮,jquery,radio-button,Jquery,Radio Button,当所选无线电输入为“是”/“否”时,我试图用ID#edate隐藏/显示div。下面是我的代码 <div id="edate"> <label>End date</label> <input name="enddate" placeholder="" class="form-control" type="date"> </div> <div> <label>Contin

当所选无线电输入为“是”/“否”时,我试图用ID
#edate
隐藏/显示
div
。下面是我的代码

 <div id="edate">
    <label>End date</label>
    <input name="enddate" placeholder="" class="form-control" type="date">      
   </div>
   <div>
  <label>Continue</label>
  <input name="continue" id="continue" value="1" type="radio"> Yes </label>
  <input name="continue" id="nocontinue" value="0"  type="radio"> No </label>
 </div>
 <script src="jquery-2.1.4.min.js"></script>
 <script type="text/javascript">
 $(document).ready(function() {
    if (data.continue == 1) {
        $("#nocontinue").removeAttr('checked');
        $("#continue").attr('checked', 'checked'); 
        $("#edate").hide();
    } else {
        $("#continue").removeAttr('checked');
        $("#nocontinue").attr('checked', 'checked');
        $("#edate").show();
    }

});
</script>

结束日期
继续
对
不
$(文档).ready(函数(){
如果(data.continue==1){
$(“#nocontinue”).removeAttr('checked');
$(“#继续”).attr('checked','checked');
$(“#edate”).hide();
}否则{
$(“#continue”).removeAttr('checked');
$(“#nocontinue”).attr('checked','checked');
$(“#edate”).show();
}
});

单击选项时,执行以下操作:

$('#continue').on('click', function() {
    $("#edate").hide();
});

单击选项时,执行以下操作:

$('#continue').on('click', function() {
    $("#edate").hide();
});
$(文档).ready(函数(){
$(“#继续”)。在('单击',函数()上{
$(“#edate”).hide();
}); 
$(“#nocontinue”)。在('click',function()上{
$(“#edate”).show();
}); 
});

结束日期
继续
对
不
$(文档).ready(函数(){
$(“#继续”)。在('单击',函数()上{
$(“#edate”).hide();
}); 
$(“#nocontinue”)。在('click',function()上{
$(“#edate”).show();
}); 
});

结束日期
继续
对
不

这种方法怎么样:

HTML


工作小提琴:这种方法怎么样:

HTML


工作小提琴:这个问题很容易找到

以下是我在论坛上搜索2分钟后发现的一些代码:

HTML

 <div id="edate">
    <label>End date</label>
    <input name="enddate" placeholder="" class="form-control" type="date">      
   </div>
   <div>
  <label>Continue</label>
  <input name="continue" id="continue" value="1" type="radio"> Yes </label>
  <input name="continue" id="nocontinue" value="0"  type="radio"> No </label>
 </div>

这个问题很容易在上面找到

以下是我在论坛上搜索2分钟后发现的一些代码:

HTML

 <div id="edate">
    <label>End date</label>
    <input name="enddate" placeholder="" class="form-control" type="date">      
   </div>
   <div>
  <label>Continue</label>
  <input name="continue" id="continue" value="1" type="radio"> Yes </label>
  <input name="continue" id="nocontinue" value="0"  type="radio"> No </label>
 </div>
jsfiddle:


jsIDLE:

为无线电组使用公共事件。另外,如果默认值为“是”,则将其设置为在HTML中选中

$(function(){

$('input[name=continue]').on('click',function(){      
  if($(this).val() == "1"){
      $('#edate').show();
    }else{
    $('#edate').hide();
    }

});

});

对无线电组使用公共事件。另外,如果默认值为“是”,则将其设置为在HTML中选中

$(function(){

$('input[name=continue]').on('click',function(){      
  if($(this).val() == "1"){
      $('#edate').show();
    }else{
    $('#edate').hide();
    }

});

});

您在文档准备就绪时运行代码,而不是在用户单击时。什么是
数据。是否继续
?您不需要更改按钮的
选中的
属性,这会自动发生。您在文档准备就绪时运行代码,当用户单击时不会。什么是
数据。是否继续
?您不需要更改按钮的
选中属性,这会自动发生。我认为这是最好的方法。聪明而简单。谢谢@AdrienLeber。我认为这是最好的方法。聪明简单。谢谢@AdrienLeber。
$(function(){

$('input[name=continue]').on('click',function(){      
  if($(this).val() == "1"){
      $('#edate').show();
    }else{
    $('#edate').hide();
    }

});

});