当我再次单击复选框时,如何删除选中的属性

How to remove checked attr on a checkbox when I click it again

本文关键字:删除 属性 何删除 单击 复选框      更新时间:2023-09-26

我如何做到这一点:当我单击一个复选框,但我再次单击它以删除选中的复选框时,$(".continuar").removeClass("ver");

我的意思是,当我单击一个复选框时,下一个按钮会出现,如果我单击第二个复选框,它会变为选中,但我希望这样:当我再次单击第一个或第二个框取消选中时,我希望按钮消失。

这正是我想要的:复选框1 unchecked=$(".contanistar").addClass("ver");在复选框2中unchecked=$(".contandar").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 &raquo;</button>

如果单击输入,则需要知道是否选中。您的按钮init$('#button').hide();或显示:无。

<div id="button" style="display:none;">YOUR BUTTON</div>
<input class="opc1" type="checkbox" value="1" />
<input class="opc2" type="checkbox" value="2" />
$('.opc1').on("click",function(){
  if($(this).prop('checked')) {
    $('#button').show();
  }else{
   $('#button').show();
  }
});
$('.opc2').on("click",function(){
  if($(this).prop('checked')) {
    $('#button').hide();
    //Also you can use $('#button').remove(); but if you need show this before don't remove.
  }
});