我该怎么做:$(".continuar").removeClass("ver");
当我单击一个复选框但再次单击它以删除选中的复选框时?
我的意思是,当我单击一个复选框时,接下来会出现按钮,如果我单击第二个复选框,它会更改为选中状态,但我想要这样:当我再次单击第一个或第二个复选框取消选中时,我希望按钮消失。
这正是我想要的:复选框 1 未选中 = $(".continuar").addClass("ver");复选框 2 未选中时也是如此 = $(".continuar").addClass("ver");
我说的是这个按钮
<div class='continuar'>
<input type="button" onclick="siguiente()" value="Continuar" class="boton" />
</div>
<input class="opc1" type="checkbox" value="1" onClick="Califica(1)" />
<input class="opc2" type="checkbox" value="2" onClick="Califica(2)" />
function Califica(opc) {
$(".continuar").addClass("ver");
respuestas[pMin]=opc;
if (opc==1) {
$("#p"+pMin+" .respuesta .opciones .opc1").attr('checked', true);
$("#p"+pMin+" .respuesta .opciones .opc2").attr('checked', false);
} else if (opc==2) {
$("#p"+pMin+" .respuesta .opciones .opc1").attr('checked', false);
$("#p"+pMin+" .respuesta .opciones .opc2").attr('checked', true );
} else if(opc == 1 || opc == 2) {
$("#p"+pMin+" .respuesta .opciones .opc1").removeAttr('checked');
$("#p"+pMin+" .respuesta .opciones .opc2").removeAttr('checked');
}
}
我尝试使用 Netzach 评论执行此操作,但没有成功
函数 Califica(opc){
$(".continuar").addClass("ver");
respuestas[pMin]=opc;
if (opc==1){
$("#p"+pMin+" .respuesta .opciones .opc1").attr('checked', true);
$("#p"+pMin+" .respuesta .opciones .opc2").attr('checked', false);
$('.opc1').on("click",function(){
if($(this).attr('checked')) {
$('.button').show();
}else{
$('.button').hide();
}
});
}else if (opc==2){
$("#p"+pMin+" .respuesta .opciones .opc1").attr('checked', false);
$("#p"+pMin+" .respuesta .opciones .opc2").attr('checked', true );
$('.opc2').on("click",function(){
if($(this).attr('checked')) {
$('#button').hide();
}
});
}
}
最佳答案
我不确定你的意思,但如果我理解你的意思,你就在寻找这样的东西:
button{
display:none;
}
input:checked + input:checked + button{
display:block !important;
}
Please accept the terms of Conditions<input type="checkbox">
and the License Agreement<input type="checkbox">, thanks!
<button>Thanks, proceed »</button>
关于javascript - 当我再次单击复选框时如何删除复选框上的选中属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33875348/