检查一个复选框组中的客户方的复选框选中中 [英] Check if a checkbox is checked in a group of checkboxes in clientside

查看:113
本文介绍了检查一个复选框组中的客户方的复选框选中中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意,该方案是ASP.NET Web表单+大师 - 内容页,其中搞乱了IDS的结果。
我有,说,三个复选框

Please note that the scenario is ASP.NET Webforms + Master - Content page which mess up the ids.
I have, say, three checkboxes

<asp:CheckBox ID="chkConsultantQuality" runat="server" 
            CssClass="company"/>
<asp:CheckBox ID="chkConsultantEnvironment" runat="server" 
            CssClass="company"/>
<asp:CheckBox ID="chkConsultantSafety" runat="server" 
            CssClass="company"/>

我想根据以下条件做出 DIV ID =CompanyPanel每个复选框的click事件

I would like to make a div id="CompanyPanel" on click event of each checkbox according to the following condition


  1. 可见,如果任何一个复选框被选中。

  2. 隐若所有的复选框都未选中。

我打算使用jQuery,因为我是按类名选择。我可以检查每一个检查标志和 jQuery.each 做的类='公司'。结果
任何更好的想法?

I am planning to use jQuery since I am selecting by class name. I could do it with jQuery.each on the class='company' by checking each for a checked flag.
Any better ideas?

推荐答案

有一个:检查 http://api.jquery.com/checked-selector/ )选择你可以使用:

There is a :checked ( http://api.jquery.com/checked-selector/ ) selector you can use :

<script>
    $(document).ready(function() {
        $(".company input").click(function() {
            var cnt = $(".company input:checked").length;

            if( cnt == 0)
            {
               // none checked
               $('#CompanyPanel').hide();
            }
            else
            {
               // any checked
               $('#CompanyPanel').show();
            }
        });
    });
</script>

您可能要添加(或使用)一个ID,这些复选框的容器上,以优化选择速度。

至于asp.net上的控件搞乱了客户端ID,您可以使用

As for asp.net messing up client ids on controls, you can use

$('<% =MyControl.ClientID %>')

这篇关于检查一个复选框组中的客户方的复选框选中中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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