简体   繁体   English

使用jQuery从复选框列表中获取选定的项目

[英]Get selected items from checkbox list with jQuery

How to get the selected items values of checkBoxList in button click event in 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"/> 

just use an attribute selector like On click of button you can loop trough all checked values like 只需使用诸如按钮之类的属性选择器,就可以循环遍历所有选中的值,例如

  $("#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