jquery hide show not work in单选按钮
当所选无线电输入为“是”/“否”时,我试图用IDjquery 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
#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();
}
});
});