0

asp:CheckBoxListデータベースからアイテムをロードするがあります。

いいえを示すスクリプトを書きたいです。各チェックでチェックされたチェックボックスの。
私のaspxページは次のとおりです:

<div id="rfd-demo-zone2" class="placeholderContent accordionEmpGroup-child-subGroup-container">
   <asp:CheckBoxList  ID="ckbList2DesignationUc" runat="Server" RepeatLayout="Flow" RepeatDirection="Horizontal" Width="100%" ></asp:CheckBoxList>          
</div>

脚本 :

<script type="text/javascript">
    $('#ckbList2DesignationUc input:checked').each(function () {
        alert('hi');
    });
</script> 

上記のスクリプトでは、アラートを取得しようとしていますが、表示されていません

4

5 に答える 5

0

クライアント側:

 $('.CheckBoxList').each(function () {
           var items = new Array();
               $(this).find("input:checkbox").each(function () {
                   if ($(this).attr("checked") == true) {
                        items[items.length] = $(this).next().html();
                     }
                   });
                   $(this).parent().find('.txtList').val(items.toString());
             });

HTML マークアップ:

<asp:TextBox runat="server" ID="txtabc" CssClass="txtList txtformatcss" Width="160px" ViewStateMode="Disabled"></asp:TextBox>
    <asp:CheckBoxList ID="chkabc" runat="server"                                      
         RepeatLayout="Flow" CssClass="CheckBoxList">
 </asp:CheckBoxList>

これは、チェックボックスリスト CheckBoxListコントロールで指定されたクラス名です

于 2013-01-22T05:50:55.933 に答える
0

考えられる解決策:

<div id="rfd-demo-zone2" class="placeholderContent accordionEmpGroup-child-subGroup-container">
      <asp:CheckBoxList  ID="ckbList2DesignationUc" runat="Server" RepeatLayout="Flow" RepeatDirection="Horizontal" Width="100%" >
      </asp:CheckBoxList>          
 </div>

そしてそれにアクセスします:

 $("#<%=ckbList2DesignationUc.ClientID %> input[type=checkbox]:checked").each(function() {  
      alert('checked');
  });  
于 2013-01-22T05:27:45.060 に答える
0

以下のコードを試してください:

解決策-1チェックボックスをオン にするたびに、チェックボックスでチェックされたアイテムの値がアラートに表示されます。

Javascript コード :

< script type="text/javascript">

         function itemClick(radioButton) {
             var Control;
             var selectedItems;
             selectedItems = '';
             Control = document.getElementById("<%=ckbList2DesignationUc.ClientID %>").getElementsByTagName("input");
             for (var i = 0; i < Control.length; i++) {
                 if (Control[i].checked == true)
                     selectedItems += i.toString()+',';
             }
             alert(selectedItems);
         }

</script>

ASPX コード :

protected void Page_Load(object sender, EventArgs e)
    {
        for (int index = 0; index < 10; index++)
        {
            ckbList2DesignationUc.Items.Add(new ListItem("Item" + index, index.ToString()));
        }
        foreach (ListItem Li in ckbList2DesignationUc.Items)
        {
            Li.Attributes.Add("onclick", "return itemClick()");
        }

    }

Jquery を使用して必要なソリューション:

ソリューション-2

< script type="text/javascript">

    $(document).ready(function () {
        var selectedCheckBoxes = '';
        $('#ckbList2DesignationUc').each(function () {
            var items = new Array();
            $(this).find("input:checkbox").each(function () {
                $(this).click(function () {
                    selectedCheckBoxes += $(this).val() + ",";
                    alert(selectedCheckBoxes);
                });
            });
        });

    });
< /script>

< asp:CheckBoxList  ID="ckbList2DesignationUc" runat="Server" RepeatLayout="Flow" RepeatDirection="Horizontal" Width="100%">
                < /asp:CheckBoxList> 
于 2013-01-22T05:37:26.797 に答える
0

これはあなたを助けるかもしれません:スクリプトタグ内だけでなくコードビハインドファイルでも使用できますenable AutoPostBack property of checkboxlist to true

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
    int i=0;            
    foreach (ListItem li in CheckBoxList1.Items)
    {
        if (li.Selected)
            i++;
    }
    Response.Write(i);           
}
于 2013-01-22T09:37:18.660 に答える
0

スクリプトをdocument.readyに配置して、スクリプトに html 要素を使用できるようにし、属性を含むセレクターを使用して、チェックボックス リストのチェックボックスを見つけます。

<script type="text/javascript">
     $(document).ready(function(){
        $('[id*=ckbList2DesignationUc]:checked').each(function () {
            alert('hi');
        });
     });
</script> 

チェックボックスの変更時にイベントを発生させる

<script type="text/javascript">
     $(document).ready(function(){
        $('[id*=ckbList2DesignationUc]').change(function () {
            alert(this.id);
        });
     });
</script> 
于 2013-01-22T05:10:07.950 に答える