如何获得复选框列表当前选定的项目值 [英] How can I get checkboxlist currently selected item value

查看:94
本文介绍了如何获得复选框列表当前选定的项目值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框列表.当我检查了一个项目后,我将获得选定的项目值(不是所有选定的项目值,只有我现在选择的值),我该如何在jquery中做到这一点.

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.

这是我的代码:

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

推荐答案

您可以为所有复选框注册一个click事件处理程序,事件处理程序this内将指向单击的复选框

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

如果jQuery> = 1.7

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')
    }
});

如果jQuery< 1.7

if jQuery < 1.7

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

这篇关于如何获得复选框列表当前选定的项目值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆