2015-08-20 83 views
-1

我想,當我選擇其他複選框,並再次激活它,當我取消選擇其他複選框,取消複選框時停用複選框。選擇另一個與jQuery

我有此片段:

$(document).ready(function(){ 
     $('#inputManholeStrDist1').click(function(){ 
      $("#inputManhole_LC_Dist").prop("disabled", !this.checked); 

     }); 
    }); 

但它是反向工程。當我最初點擊複選框時,什麼也沒有發生,當我點擊它時,其他複選框被禁用。 我在這裏錯過了什麼?

+0

它不是一個單選按鈕,以扭轉你的病情。 – user1919

+2

@dkar:不,它不是;但你複製的無線電''使用的複選框出於某種原因的功能,並與傳統的用戶界面的期望可能混淆你的用戶突破。爲什麼? –

+0

@大衛·托馬斯:你怎麼可以從我粘貼,我用一個單選按鈕的代碼的結論呢?哪一行實際上表示? – user1919

回答

2

你需要,只要你想禁用狀態是一樣的複選框的選中狀態

$(document).ready(function() { 
 
    $('#inputManholeStrDist1').change(function() { 
 
     $("#inputManhole_LC_Dist").prop("disabled", this.checked); 
 
    }).change();//to set the initial state 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<input type="checkbox" id="inputManholeStrDist1" checked /> 
 
<input type="checkbox" id="inputManhole_LC_Dist" />

1
$(document).ready(function(){ 
    $("#inputManholeStrDist1").click(function(){ 
    if($(this).is(':checked')){ 
     $("#inputManhole_LC_Dist").attr("disabled","disabled"); 
    }else{ 
     $("#inputManhole_LC_Dist").removeAttr("disabled"); 
    } 
    }); 
}); 
相關問題