2011-12-14 28 views
1

我想在我的複選框列表中啓用複選框。這並不在我的解決方案工作的唯一一件事就是在IE9的跨度中移除已停用的屬性,它工作在FF:試圖啓用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 runat="server"> 
    <title></title> 
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> 
    <script type="text/javascript"> 

     function enablebut() { 
      $('#CheckBoxList1_0').removeAttr('disabled'); 
      $('#CheckBoxList1_0').closest('span').removeAttr('disabled'); 

     } 

    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <button onclick="enablebut();">enable</button> 
    <div> 
     <asp:CheckBoxList ID="CheckBoxList1" Enabled='false' runat="server"> 
      <asp:ListItem Text="een"></asp:ListItem> 
      <asp:ListItem Text="twee"></asp:ListItem> 
     </asp:CheckBoxList> 
    </div> 
    </form> 
</body> 
</html> 

回答

1

添加type="button"屬性,以防止提交(回發)。

<button type="button" onclick="enablebut();">enable</button> 

或者

<input type="button" onclick="enablebut();" value="enable"/> 
+0

它不能在IE9中工作:( – user603007 2011-12-14 10:43:26

0

我想,而不是傳遞函數通過JavaScript,你應該因爲你使用jQuery

寫的document.ready函數中下面的代碼
$(document).ready(function() { 
      $('#CheckBoxList1_0').attr('disabled',''); 
    }) 

編輯:整頁代碼:

<!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 runat="server"> 
    <title></title> 
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> 
    <script type="text/javascript"> 

     $(document).ready(function() { 
      $('#CheckBoxList1_0').attr('disabled',''); 
    }) 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <button type="button">enable</button> 
    <div> 
     <asp:CheckBoxList ID="CheckBoxList1" Enabled='false' runat="server"> 
      <asp:ListItem Text="een"></asp:ListItem> 
      <asp:ListItem Text="twee"></asp:ListItem> 
     </asp:CheckBoxList> 
    </div> 
    </form> 
</body> 
</html> 
+0

它不能在IE9的工作? – user603007 2011-12-14 10:43:12

0

及其在IE8不wroking,這裏是下面的代碼

<asp:CheckBoxList ID="chkList" runat="server" Enabled="false" > 
          <asp:ListItem Text="1" Value="1"></asp:ListItem> 
          <asp:ListItem Text="2" Value="2"></asp:ListItem> 

         </asp:CheckBoxList> 


      <asp:Button ID="btnFoo" runat="server" Text="Test" /> 

<script type="text/javascript" language="javascript"> 
       $(document).ready(function() { 

        $('#<% = btnFoo.ClientID %>').click(function() { 
         //var targetValue = 2; 
         var items = $('#<% = chkList.ClientID %> input:checkbox'); 
         for (var i = 0; i < items.length; i++) { 
           //alert(i); 
          //if (items[i].value == targetValue) { 
          items[i].checked = true; 

           // break; 
          //} 
         } 

$( '#<%= chkList.ClientID%>輸入:複選框')removeAttr( '禁用');。返回false; }) });

相關問題