<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>
遵循条件sholud实现启用每个复选框,
任何人都可以帮我解决一个简单的问题。
答案 0 :(得分: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);
}
我不明白你的第四个要求。 希望这有帮助