簡體   English   中英

使用jQuery從復選框列表中獲取選定的項目

[英]Get selected items from checkbox list with jQuery

如何在jQuery的按鈕單擊事件中獲取checkBoxList的選定項值...

    <asp:CheckBoxList ID="check_list" runat="server">
        <asp:ListItem Text ="One" Value="1"></asp:ListItem>
        <asp:ListItem Text ="Two" Value="2"></asp:ListItem>
        <asp:ListItem Text ="Three" Value="3"></asp:ListItem>
    </asp:CheckBoxList>
<input type="button" id="btn_click" value="Click"/> 

只需使用諸如按鈕之類的屬性選擇器,就可以循環遍歷所有選中的值,例如

  $("#btn_click").click(function(){
    $("[id*=check_list] input[type=checkbox]:checked").each(function () {
           // add $(this).val() to your array
      });
    });

請參閱API中描述的jQuery :checked選擇器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM