如何在点击一个复选框时禁用其他复选框?

问题描述:

我该怎么做?如何在点击一个复选框时禁用其他复选框?

  • 如果点击Replacement of Registration,禁用Honorable DismissalEntrance Exam
  • 如果Good Moral Certificate被点击时,禁用Entrace Exam
  • 如果Honorable Dismissal,禁用DiplomaCUE RequestCMI RequestEntrance Exam
  • 如果点击Transcript of Record,禁用CUE RequestCMI RequestEntrance Exam
  • 如果Entrance Exam,禁用所有

<input type="checkbox" name="ac_description[]" value="Replacement_of_Registration"> 
<input type="checkbox" name="ac_description[]" value="Good_Moral_Certificate"> 
<input type="checkbox" name="ac_description[]" value="Honorable_Dismissal " > 
<input type="checkbox" name="ac_description[]" value="Transcript_of_Record"> 
<input type="checkbox" name="ac_description[]" value="Diploma"> 
<input type="checkbox" name="ac_description[]" value="CUE_Request"> 
<input type="checkbox" name="ac_description[]" value="CMI_Request"> 
<input type="checkbox" name="ac_description[]" value="Entrance_Exam"> 
<input type="checkbox" name="ac_description[]" value="School_fees-Medical/Dental_Laboratory"> 
<input type="checkbox" name="ac_description[]" value="School_fees-Transcript/Honorable"> 
<input type="checkbox" name="ac_description[]" value="School_fees-Library"> 
<input type="checkbox" name="ac_description[]" value="Affiliation_Fees"> 
+0

你们是不是要禁止所有每当一个盒子已被检查其他框或禁用一定的盒子? – spiritwalker

+0

因此更改事件和逻辑 – epascarello

+0

-if单击替换注册,禁用授予退出和入学考试 -if单击良好道德证书,禁用入学考试 - 如果授予退休,禁用文凭,CUE请求,CMI申请,入学考试 -if录制成绩单被点击,禁用CUE请求,CMI请求,入学考试 -if入学考试,全部停用 –

你会在输入标签的结尾,例如把残疾:

<input type = "checkbox"name = "ac_description[]" value = "Good_Moral_Certificate" > 
<input type = "checkbox" name = "ac_description[]" value = "Honorable_Dismissal " > 
<input type = "checkbox" name = "ac_description[]" value = "Transcript_of_Record"> 
<input type = "checkbox" name = "ac_description[]" value = "Diploma" disabled> 

第四复选框将被禁用。你可以使用jQuery来操纵它。 使用jQuery你可以让一个事件发生在复选框被触发时,它将禁用的属性应用到其他框。 看看这个答案:Disable/enable an input with jQuery?

如果你想禁用一个组,给每组输入分配一个类,然后使用jQuery来改变它们。看看这篇文章,以及:Catch checked change event of a checkbox

这里是你可能想尝试什么样的例子:

$('.class_name').each(function(){ 
$this.onClick(function(){ 
if($(this).is(':checked')){ 
    $('.class_name').each(function(){ 
    if($(this).not(':checked')){ 
     $(this).prop('disabled', true); 
    } 
    }) 
} 

}) });

+0

如何制作一个jQuery和脚本?谢谢 –

+0

您可能想为每个分组创建一个班级,您只能从中选择一个复选框。然后为每个类分配一个监听器。 – KingLagalot

拼凑此代码段从最新从你的问题的理解,

$("input[type='checkbox']").click(function(){ 
    var val = $(this).attr('value'); 
    switch(val) { 
    case 'Replacement_of_Registration': 
    if($(this).is(':checked')) 
     $("input[value='Honorable_Dismissal '], input[value='Entrance_Exam']").prop('disabled',true); 
    else 
     $("input[value='Honorable_Dismissal '], input[value='Entrance_Exam']").prop('disabled',false); 
    break; 
    case 'Good_Moral_Certificate': 
    if($(this).is(':checked')) 
     $("input[value='Entrance_Exam']").prop('disabled',true); 
    else 
     $("input[value='Entrance_Exam']").prop('disabled',false); 
    break; 
    case 'Honorable_Dismissal ': 
    if($(this).is(':checked')) 
     $("input[value='Diploma'], input[value='CUE_Request'], input[value='CMI_Request'], input[value='Entrance_Exam']").prop('disabled',true); 
    else 
     $("input[value='Diploma'], input[value='CUE_Request'], input[value='CMI_Request'], input[value='Entrance_Exam']").prop('disabled',false); 
    break; 
    case 'Transcript_of_Record': 
    if($(this).is(':checked')) 
     $("input[value='CUE_Request'], input[value='CMI_Request'], input[value='Entrance_Exam']").prop('disabled',true); 
    else 
     $("input[value='CUE_Request'], input[value='CMI_Request'], input[value='Entrance_Exam']").prop('disabled',false); 
    break; 
    case 'Entrance_Exam': 
    if($(this).is(':checked')) 
     $("input[name='ac_description[]']").not(this).prop('disabled',true); 
    else 
     $("input[name='ac_description[]']").not(this).prop('disabled',false); 
    break; 
}); 
+0

仍然没有运作。 –

+0

什么不起作用,你可以更具体。 –