2011-05-02 61 views
0
<div id="c_b" class="checkbox-elemet"> 
    <div class="checkbox"> 
     <input type="checkbox" value="nri" id="nri" name="status[]"><label for="nri">NRI</label></div> 
     <div class="checkbox"><input type="checkbox" id="resident" value="resident" name="status[]"><label for="resident">Resident</label></div> 
     <div class="checkbox"><input type="checkbox" disabled="true" id="salaried" value="salaried" name="status[]"><label for="salaried">Salaried</label></div> 
     <div class="checkbox"><input type="checkbox" disabled="true" id="self_employed" value="self_employed" name="status[]"><label for="self_employed">Self</label></div> 
     <div class="checkbox"><input type="checkbox" disabled="true" id="govt_employee" value="govt_employee" name="status[]"><label for="govt_employee">Govt.</label></div> 
     <div class="checkbox"><input type="checkbox" disabled="true" id="others" value="others" name="status[]"><label for="others">Others</label></div> 
</div> 

繼condtions sholud履行使每個複選框,與多重條件複選框來過濾使用jQuery

  1. NRI,居民應首先使 ,所有其他被禁止
  2. NRI檢查:只有工薪和 其他人啓用
  3. NRI和工資檢查:沒有其他 啓用
  4. 居民檢查:工資,官立,其他,自應 使
  5. 居民和工薪檢查: 官立。和其他使
  6. 居民和自我檢查:沒有其他 啓用

任何人都可以幫我用一個簡單的解決方案。

+0

這是我的腳本:http://jsfiddle.net/kyathi/mFPNa/ – abhis 2011-05-02 07:49:29

回答

0

你的代碼可能是這樣:

$(document).ready(function(){ 
    //1. NRI,Resident should enable initially, all other are disabled 
    disableAll(); $("#nri", "#resident").attr("disabled", false); 
    //Req 2 
    $("#c_b :checkbox").change(function(){ 
     //2. NRI checked : Only Salaried and Others enable 
     if(isChecked("#nri")){ disableAll(); enable("#salaried, #others"); } 
     //3. NRI and Salaried checked : No other Enable 
     if(isChecked("#nri") && isChecked("#salaried")){ disableAll(); enable("#nri, #salaried"); } 
     //4. Resident checked : All child should enable 
     //what is child? 
     //5. Resident and Salaried checked : Govt. and Other enable 
     if(isChecked("#resident") && isChecked("#salaried")){ enable("#govt_employee, #others"); } 
     // 6. Resident and Self checked : No other Enable 
     if(isChecked("#resident") && isChecked("#self_employed")){ disableAll(); enable("#resident, #self_employed"); } 
    }); 
    }); 
    function disableAll(){ 
    $("#c_b :checkbox").attr("disabled", true); 
    }  
    function isChecked(id){ 
    return $(id).is(":checked"); 
    } 
    function enable(sel){ 
    $(sel).attr("disabled", false); 
    } 

我不明白你的第四個要求。 希望這可以幫助

+0

感謝您的迴應。讓我嘗試 – abhis 2011-05-02 07:52:41