问题
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