【问题标题】:Select or unselect checkboxlist item using jquery on checkboxlist change在复选框列表更改时使用 jquery 选择或取消选择复选框列表项
【发布时间】:2014-08-07 19:13:26
【问题描述】:

我的页面上有一个 Asp.net 复选框列表控件 (id:MyChklst),在选择更改时我正在调用 Jquery 函数。

但问题是我想根据 on-change 函数中的一些验证取消选中或更改项目的颜色。

下面是我正在使用的代码

jquery函数:

        $('#MyChklst').on('click', ':checkbox', function () {
            if ($(this).is(':checked')) {
                 alert($(this).val());  // Working
                // alert($(this).text());  Not Working
                //$(this).css("background-color");  Not Working
                //$(this).attr('checked','false'); Not Working
            }
        });

请帮帮我,提前谢谢

【问题讨论】:

    标签: jquery asp.net checkboxlist selectlistitem


    【解决方案1】:

    试试看:

    • 确保您使用的是控件的 clientID,确保“MyChklst”是控件 ID:
    <asp:CheckBoxList runat="server" ID="MyChklst">
    
    • 定位复选框旁边的标签,Firefox/Chrome > 检查 asp.net 如何呈现最终的 HTML。
    • 使用 [prop] : http://api.jquery.com/prop/
    $(document).ready(function () {
        $('#<%=MyChklst.ClientID %>').on('click', ':checkbox', function () {
            if ($(this).is(':checked')) {
                alert($(this).val());  
                alert($(this).next('label').text()); 
                $(this).next('label').css("background-color","yellow"); 
                $(this).prop('checked',false); 
            }
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多