2011-12-14 13 views
1

私のチェックボックスリストでチェックボックスを有効にしようとしています。私の解決策では動作しない唯一のことは、IE9でのスパンからのdisabled属性を削除することです、それは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

0

私の代わりにはJavaScriptを通じて機能を渡すのあなたはjQueryの

$(document).ready(function() { 
      $('#CheckBoxList1_0').attr('disabled',''); 
    }) 

にEDITを使用しているので、あなたがdocument.ready関数の内部で、次のコードを書くべきだと思います。ページコード全体:

<!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

+0

IE 7,8,9 Chrome、Mozilla、3.5から8.0バージョンで同じテストをしました – Murtaza

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( '無効');偽を返します。 }) });

関連する問題