选中复选框后确认框

squ*_*c77 2 checkbox jquery confirm

根据我在这里找到的东西,我一直在尝试不同的方法,但无济于事.有人可以引导我朝着正确的方向前进吗?在选中或取消选中复选框时,我想抛出确认,然后根据用户选择选中复选框或选中复选框.谢谢!

$('input:checkbox').click(function(){
     var checked = $("input:checked").length; 
    if (checked == 0){ 
if(confirm('Are you sure you want to discontinue this program?')){
    (':checkbox:checked').removeAttr('checked');
}
    }  else

    { 
if(confirm('Are you sure you want to resume use of this program?'))            
(':checkbox:checked').attr('checked');
    } 
Run Code Online (Sandbox Code Playgroud)

HTML

<table>
  <tr>
    <td><input name="input" type="checkbox" value="" /></td>
    <td>Because We Care</td>
   </tr>
      <tr>
                     <td><input name="" type="checkbox" value="" /></td>
                     <td>Some Unused Program</td>
                     </tr>
Run Code Online (Sandbox Code Playgroud)

Zbi*_*iew 6

您的代码中存在一些语法和逻辑缺陷,请尝试以下方法:

$('input:checkbox').click(function(){
    var checked = $(this).is(':checked');
    if(checked) {
        if(!confirm('Are you sure you want to resume use of this program?')){         
            $(this).removeAttr('checked');
        }
    } else if(!confirm('Are you sure you want to discontinue this program?')){
        $(this).attr("checked", "checked");
    }
}?);?
Run Code Online (Sandbox Code Playgroud)

的jsfiddle