2009-10-29 3 views
1

하나만 제외하고 모든 확인란이 비활성화되었습니다. 그 확인란을 클릭하면 모든 확인란을 활성화하고 싶습니다. 확인란을 선택하지 않으면 다른 모든 확인란이 비활성화 된 상태로 유지됩니다. 누구든지 이걸 도와주세요. 나는Jquery를 사용하여 다른 확인란을 클릭하면 확인란이 사용되도록 설정됩니다.

$(document).ready(function() {<br> 
    if ($('#mainCheckbox').is(':checked')) {<br> 
    $(".otherCheckbox").removeAttr("disabled"); 
    }  
}); 

를 사용하는 것을 시도했다 그러나 이것은 나를 위해 작동하지 않습니다. 당신은 또한 HTML을 게시 할 수 있습니다 후 더 도움이 될 것입니다 경우

답변

5

이 날

<input type="checkbox" id="chkMain" /><br 
<input class="child" type="checkbox" id="chk1" disabled="true" /> 
<input class="child" type="checkbox" id="chk2" disabled="true" /> 
<input class="child" type="checkbox" id="chk3" disabled="true" /> 
<input class="child" type="checkbox" id="chk4" disabled="true" /> 
<input class="child" type="checkbox" id="chk5" disabled="true" /> 

$(function(){ 
    $("#chkMain").click (function() { 

    if (!$(this).is (":checked")) 
    { 
     $(".child").attr ("disabled" , true); 
    } 
    else 
    { 
     $(".child").removeAttr ("disabled"); 
    } 
    }); 
}); 

Working Demo

을 위해 잘 작동합니다.

+1

덕분에 많이! 이게 내가 찾던 바로 그거야 ... – Shruti

1

이 노력하고 있습니다 :

if($("#mainCheckbox").is(":checked")){ 
    $("input:checkbox").not(this).removeAttr("disabled"); 
} 
else{ 
    $("input:checkbox").not(this).attr("disabled","true"); 
} 
0

가 여기에 솔루션 (각 기능에주의)이다 :

function toogleOthersIf(aBoolean) { 
    $(".otherCheckBox").each(function() { 
     if (aBoolean) { 
      $(this).removeAttr("disabled"); 
     } else { 
      $(this).attr("disabled", "disabled"); 
     } 
    }); 
} 

$(document).ready(function(){ 
    $('#mainCheckBox').click(function(e) { 
     toogleOthersIf($('#mainCheckBox:checked').length > 0); 
    }); 

    toogleOthersIf(false); 
}); 
+0

흠이 각각 필요하지 않습니다 .. –

관련 문제