2013-09-30 36 views
0

我有一個列表視圖及其包含n個複選框。點擊第一個複選框時,我想要啓用/禁用。 我已經寫了一個代碼在jQuery中。但它採取頁面中的所有複選框。我需要啓用/禁用所選的行。在ListView控件如何啓用/禁用一行listview中的所有控件。同時點擊列表視圖中的複選框

function EnableCurrentRowControls(chkID) 
{ 
     var chkBox = document.getElementById(chkID); 
     var chkIDList = document.getElementsByTagName("input"); 
     for (i = 0; i < chkIDList.length; i++) 
     { 
      if (chkIDList[i].type == "checkbox" && chkIDList[i].id != chkBox.id) { 

       if (chkIDList[i].type == "checkbox" && chkIDList[i].id != chkBox.id) 
        { 
         chkIDList[i].enabled = false; 
        } 
      } 
     } 
} 

調用函數

<asp:CheckBox ID="chkUserBoardMaping" OnClick="javascript:EnableCurrentRowControls(this.id)" 
                  runat="server" /> 

請看看和建議我..

+0

請添加一行呈現的HTML。所以我們可以看到如何遍歷 –

回答

1

可能有這樣的事情是想:

function EnableCurrentRowControls(element) { 
     if ($(element).closest('tr').find('input[type=checkbox][id*=chkUserBoardMaping]').is(':checked')) { 

      $(element).closest('tr').find('input[type=text][id*=myTextBox]').removeAttr("disabled"); 
     } 
     else { 
      $(element).closest('tr').find('input[type=text][id*=myTextBox]').prop("disabled"); 

     } 
    } 

你也必須改變這個 (1.只通過這個作爲參數 2.將onclick事件更改爲onchange):

<asp:CheckBox ID="chkUserBoardMaping" onchange="javascript:EnableCurrentRowControls(this)" 
                 runat="server" /> 

確保您更改了控件(myTextBox)名稱!

相關問題