這裏我需要的是,jQuery的,如果一個複選框被選中,禁用基於價值
<div id="employeedetails-relation" class="check"><div class="checkbox"> <label><input type="checkbox" name="Employeedetails[relation][]" value="1"> Father</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="2"> Mother</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="3"> Spouse</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="4"> Child1</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="5"> Child2</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="6"> Father-in-law</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="7"> Mother-in-law</label></div></div>
在這裏,如果我檢查值 或 ,則看重其他特定複選框和 複選框必須禁用。如果我檢查值以同樣的方式 或 ,則複選框值 和 必須得到禁止。
假設如果我先檢查值3,然後如果檢查值1或2,則值6和7必須被禁用。
如果我未選中值1,檢查值2,再次重視6和7必須得到禁止,或者
我的代碼:
$(\'input[type="checkbox"]\').click(function(){
if (this.checked && this.value === "1") {
$(\'#employeedetails-relation input[value="6"\').prop(\'disabled\', \'true\');
$(\'#employeedetails-relation input[value="7"\').prop(\'disabled\', \'true\');
}
elseif (!this.checked && this.value === "1")
{
$(\'#employeedetails-relation input[value="6"\').prop(\'disabled\', \'false\');
$(\'#employeedetails-relation input[value="7"\').prop(\'disabled\', \'false\');
}
告訴我們您已經嘗試 – Pawan
代碼見上面我已經更新了我的問題 –
我想這一點,它的工作,但如果檢查兩個值1和2,然後值6和7變得可以消滅,假設如果我沒有從1或2中選擇任何值,那麼值6和7變得可用 –