jquery实现全选等功能

<script type="text/javascript">
$(function () {
       // 1.选中第一列的功能大项后,自动选中该行第二列的所有功能小项。
       $(".parentfunc").click(function ()
       {
     //根据.parentfunc的选中状态改变后面的状态
      $(this).parent("span").parent("td").siblings("td").children("span").children("input").prop("checked",$(this).prop("checked"));
  })

     //2.当第二列功能小项没有全部选中时,该行第一列的复选款也要取消选中。
    $("tr td:last-child span input").click(function () {

   var num = 0;
    for (var i = 0; i < $(this).parent().parent().children().length; i++)
  {
    if ($(this).parent().parent().children(":eq("+i+")").children().prop("checked")==false)
    {
      num++;
      $(this).parent("span").parent("td").siblings("td").children("span").children("input").prop("checked", false);
    }
  if(num==0)
  {
    $(this).parent("span").parent("td").siblings("td").children("span").children("input").prop("checked",true);
  }
    }

  })
})
</script>

posted @ 2018-08-17 16:39  [value]  阅读(124)  评论(0编辑  收藏  举报