2017-09-13 227 views
-2

我該怎麼做?如何在點擊一個複選框時禁用其他複選框?

  • 如果點擊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入學考試,全部停用 –

回答

0

你會在輸入標籤的結尾,例如把殘疾:

<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

0

拼湊此代碼段從最新從你的問題的理解,

$("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

什麼不起作用,你可以更具體。 –

相關問題