Check if a checkbox is checked in a group of checkboxes in clientside

前端 未结 3 1879
忘了有多久
忘了有多久 2020-12-22 01:32

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



        
3条回答
  •  庸人自扰
    2020-12-22 02:35

    You can just wait for the click event on all checkboxes, and perform your validation there. No need for .each(). This way, you validate whenever any of the checkboxes have been checked or unchecked.

    $('input.company:checkbox').click(function(){
        if ($('input.company:checkbox:checked').length > 0)
        {
            $('div#CompanyPanel').show();
        }
        else 
        {
            $('div#CompanyPanel').hide();
        }
    });
    

    You can just optimize it a bit as well, and change according to your needs.

提交回复
热议问题