简体   繁体   中英

implement select all check boxes functionality in asp using javascript

I have a table which displays students record in asp.Now a column in that table contains a check box and also a functionality to check all the check boxes would be provided at the top. How to do that using javascript?

see demo

$(function(){

    // add multiple select / deselect functionality
    $("#selectall").click(function () {
          $('.case').attr('checked', this.checked);
    });

    // if all checkbox are selected, check the selectall checkbox
    // and viceversa
    $(".case").click(function(){

        if($(".case").length == $(".case:checked").length) {
            $("#selectall").attr("checked", "checked");
        } else {
            $("#selectall").removeAttr("checked");
        }

    });
});​

define a link anywhere, grab its event and use checked property

<a href="#" rel="checkedBoxes">Check All Boxes</a>
<a href="#" rel="uncheckedBoxes">Uncheck all Boxes</a>

<script>
   $(function() {
      $("a[rel=checkedBoxes]").live("click", function(eV) {
          eV.preventDefault();
          $("form input:checkbox").attr("checked", "checked");
      }
      $("a[rel=uncheckedBoxes]").live("click", function(eV) {
          eV.preventDefault();
          $("form input:checkbox").attr("checked", "");
      }

   });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM