2011-01-05 16 views
1
<input type="checkbox" id="chkMain" /> 
<input type="checkbox" id="chkMain1" /> 
<input type="checkbox" id="chkMain2" /> 
<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" /> 
<input class="child" type="checkbox" id="chk6" disabled="true" /> 
<input class="child" type="checkbox" id="chk7" disabled="true" /> 


$(function(){ 
     $("input[id^=chkMain]").click (function() { 
      if(!$(this).is (":checked")){  
       $(".child").attr ("disabled" , true); 

      }  
      else{  
       $(".child").removeAttr ("disabled");  
      } 
     }); 
    });

Dies aktiviert alle untergeordneten Felder, wenn entweder chkMain oder chkMain1 oder chkMain2 aktiviert sind. was ich will ist: Wenn chkMain aktiviert ist, sollte der Code chkMain1 und chkMain2 deaktivieren, aber Kind-Boxen aktivieren. oder Wenn chkMain1 aktiviert ist, sollte der Code chkMain und chkMain2 deaktivieren, aber untergeordnete Felder aktivieren.Wählen Sie ein Kontrollkästchen aus mehreren MAIN-Kontrollkästchen, deaktivieren Sie alle anderen MAIN-Boxen, n enable child Kontrollkästchen

Antwort

0

Try this, der Trick ist, die anderen Hauptkontrollkästchen mit einem nicht Auswerter in Jquery wählen:

<input type="checkbox" id="chkMain" /> 
    <input type="checkbox" id="chkMain1" /> 
    <input type="checkbox" id="chkMain2" /> 
    <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" /> 
    <input class="child" type="checkbox" id="chk6" disabled="true" /> 
    <input class="child" type="checkbox" id="chk7" disabled="true" /> 
    <script> 
     $ 
     (
      function() 
      {   
       $("input[id^=chkMain]").click 
       ( 
        function() 
        {    
         var otherCks = $("input[id^=chkMain]").not(this); 
         if(!$(this).is(":checked")) 
         {       
          $(".child").attr("disabled" , true);    
          otherCks.removeAttr ("disabled");     
         }     
         else 
         {       
          $(".child").removeAttr ("disabled");     

          otherCks.attr("disabled" , true) 
         }    
        } 
       );  
      } 
     ); 
    </script> 
+0

dank cybernate, die gearbeitet ... – Harshil

+0

meine Antwort zu überprüfen, für alle Fälle: http://jsfiddle.net/sBgZw/ – hunter

Verwandte Themen