开发者

Need help checking all checkboxes

开发者 https://www.devze.com 2022-12-20 02:14 出处:网络
Any idea why this code is failing?I\'m doing the exact same thing somewhere else, except开发者_Python百科 I\'m using a DIV with an ID for my selector.This time I needed to use a \"CLASS name\" as my s

Any idea why this code is failing? I'm doing the exact same thing somewhere else, except开发者_Python百科 I'm using a DIV with an ID for my selector. This time I needed to use a "CLASS name" as my selector, but it doesn't work. All I want to do is check one checkbox and have it check all the checkboxes that have the same class name. Any help is appreciated, or any other ways of accomplishing the same thing in a better way are appreciated.

Thanks.

Javascript FUNCTION:

function jqCheckAll_byClass(class_name, name, check_me)
{
   if (check_me == false)
   {
      $("." + class_name + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', false);
   }
   else
   {
       $("." + class_name + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', true);
   }
}

ONCLICK EVENT:

<input type="checkbox" onclick="jqCheckAll_byClass('5_arch_chbx','5_archive_chbx', this.checked );" title="Check All" class="a_hand">

HTML:

<input type="checkbox" class="5_arch_chbx input_editible" name="5_archive_chbx" id="2087archive_chbx_id">


Remove onclick from HTML and try this one. I have also provided an id for the check all checkbox.

<input type="checkbox" id="chkAll" title="Check All" class="a_hand">

$(function(){
    $("#chkAll").click(function(){
        $(":checkbox.5_arch_chbx").attr ( "checked", $(this).attr("checked") );
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号