How can I get checkboxlist currently selected item value

倖福魔咒の 提交于 2019-12-21 17:49:11

问题


I have a checkboxlist.After when I checked an item on it I will get the selected item value(not all of the selected items values,only the which I'm slected now),How can I do it in jquery.

Here is my code:

<asp:CheckBoxList ID="CheckBoxList1" runat="server" Enabled="False">
        <asp:listitem value="1"></asp:listitem>
        <asp:listitem value="2"></asp:listitem>
        <asp:listitem value="3"></asp:listitem>
        <asp:listitem value="4"></asp:listitem>
    </asp:CheckBoxList>

回答1:


You can register a click event handler for all the checkboxes, inside the event handler this will point to the clicked checkbox

if jQuery >= 1.7

$('#CheckBoxList1').on('click', ':checkbox', function() {
    if ($(this).is(':checked')) {
        // handle checkbox check
        alert($(this).val());
    } else {
        // checkbox is unchecked
        alert('unchecked')
    }
});

if jQuery < 1.7

$('#CheckBoxList1 :checkbox').live('click', function() {
    alert($(this).is(':checked'));
});



回答2:


This will display the value of the checkbox onclick:

$('input:checkbox').click(function() {
    alert($(this).val());
});


来源:https://stackoverflow.com/questions/16142535/how-can-i-get-checkboxlist-currently-selected-item-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!