2010-02-24 68 views
0

在我的網頁我有一個錶行通常是這樣的:jQuery的複選框匹配單選按鈕列表

<tr class = "child"> 
     <td> 
      <asp:CheckBox ID="CheckBoxEyeProblems" runat="server" /> 

     </td> 
     <td align="center"> 
      <asp:RadioButtonList ID="RadioButtonListEyeProblems" 
       <asp:ListItem Value="Y">Yes</asp:ListItem> 
       <asp:ListItem Value="N">No</asp:ListItem> 
      </asp:RadioButtonList> 
     </td> 
</tr> 

我所試圖做的是禁用/啓用同一行中單選按鈕列表的複選框你的時候選中/取消選中它。

$('tr.child input:checkbox').click(function() 
{ 
    //last part of this selector is incorrect, how to correct it here? 
    var rblist = $(this).closest('tr.child').find(':input:radio'); 

    if ($(this).is(':checked')) 
    { 
     //aslo not sure how to clear selection if any from RadioButtonList here 
     rblist.attr('disabled', 'disabled');    

    } 
    else 
    { 

     rblist.removeAttr('disabled'); 

    } 

}); 

所以,這些都是我的問題。我正在使用ASP.NET 3.5。

+0

不,你不使用ASP,你使用jQuery與ASP生成的標記。向我們展示標記(HTML),而不是您的ASP代碼。 – bdl 2010-02-24 04:37:38

+0

這個頁面是主頁面下的內容頁面,所以HTML會有很多的id損壞。這可能會讓我更好地瞭解我正在嘗試做什麼。 – Victor 2010-02-24 05:00:10

回答

0

試試這個

$("tr.child td input:checkbox").click(function(){ 
    var chk = $(this); 
    //chk.closest("td").next().find("input:radio").attr("disabled",chk.attr("checked")); 
    // to remove checked attribute you can use 
    chk.closest("td").next().find("input:radio").attr("checked", false).attr("disabled",chk.attr("checked")); 
}); 
+0

感謝您的回覆。我只是想知道,如果chk.closest(「td」)能夠工作,因爲它們處於不同的「td」元素中。如何在禁用之前清除任何rb選擇? – Victor 2010-02-24 04:50:07

+0

即使這種確切的方法不起作用,首先,我只需要取消選中複選框時取消選中,但給了我一個關於如何完成我的任務的好主意 – Victor 2010-02-25 03:07:46