2011-12-14 29 views
0

我想從js啓用我的checkboxlist?這是我的代碼SOFAR:如何從javascript啓用asp.net checkboxlist?

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title></title> 
    <script> 
     function enabledCBL() { 
      document.getelementbyid('CheckBoxList1').disabled = false; 
     } 

    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <button onclick="enabledCBL()">enable</button> 
     <asp:CheckBoxList ID="CheckBoxList1" runat="server" TextAlign="Right"> 
      <asp:ListItem Text="een"> 

      </asp:ListItem> 
      <asp:ListItem Text="twee"> 

      </asp:ListItem> 
      <asp:ListItem Text="drie"> 

      </asp:ListItem> 
      <asp:ListItem Text="vier"> 

      </asp:ListItem> 
     </asp:CheckBoxList> 
    </div> 
    </form> 
</body> 
</html> 
+0

檢查CheckBoxList的真實身份你的HTML輸出 – hungneox 2011-12-14 04:43:35

+0

你的腳本有問題。 – 2011-12-14 07:19:14

回答

0

JavaScript是區分大小寫的。你的陳述必須是:

document.getElementById('CheckBoxList1').disabled = false; 

嘗試,

function enabledCBL() { 
     var tab = document.getElementById('CheckBoxList1'); 

     var checkboxes = tab.getElementsByTagName("input"); 
     for (i = 0; i < checkboxes.length; i++) 
      checkboxes[i].disabled = false; 
    } 

<button>標籤確實需要類型的屬性添加到該按鈕回發。

<button type="button" onclick="enabledCBL()"> 
      enable</button> 
+0

對不起,但你的解決方案仍然不起作用:( – user603007 2011-12-14 04:27:49

0

取消選擇在CheckBoxList的項目,但我已經厭倦了在javascript..But啓用清單的工作不適合me..Hope這代碼將幫助你。因此,我張貼在這裏。

function Validate() 
{ 
var tableBody = document.getElementById('CheckBoxList1').childNodes[0]; 
for (var i=0;i<tableBody.childNodes.length; i++) 
{ 
var currentTd = tableBody.childNodes[i].childNodes[0]; 
var listControl = currentTd.childNodes[0]; 
if (listControl.checked==true) 
{ 
listControl.checked = false; 
} 
} 
} 


<asp:CheckBoxList ID="CheckBoxList1" runat="server" TextAlign="Right"> 
     <asp:ListItem Text="aa"> 
     </asp:ListItem> 
     <asp:ListItem Text="twee"> 
     </asp:ListItem> 
     <asp:ListItem Text="drie"> 
     </asp:ListItem> 
     <asp:ListItem Text="vier"> 
     </asp:ListItem> 
    </asp:CheckBoxList> 

我已經看到了基於jQuery中您需要一個示例請參閱此鏈接Jquery