• 制作一个表格,实现可以部分选中以及全选并且置灰背景


    <!DOCTYPE html>

    <html>

    <head>

    <meta charset='UTF-8'>

    <style type="test/css">

    #table{

    color:green;

    margin:0 auto;

    300px;

    height:200px;

    font-weight:400px;

    font-size:large;

    text-align:center;}

    .select{

    background:rgba(50,50,50,0.5);

    }

    </style>

    <script src></script>

    </head>

    <body>

    <table id="table" border="1px solid blue" cellspacing='0' cellpadding='0'>

    <thead>

    <tr><th class="header"><input id="checkall" type="checkbox"name="checkall"/></th><th class=‘header‘>header</th><th class='header‘>header</th><th class='header‘>header</th>

    </thead>

    <tbody>

    <tr><td><input class='checklist' type='checkbox'  name='checklist'/></td><td>data</td><td>data</td><td>data</td>

    <tr><td><input class='checklist' type='checkbox'  name='checklist'/></td><td>data</td><td>data</td><td>data</td>

    <tr><td><input class='checklist' type='checkbox'  name='checklist'/></td><td>data</td><td>data</td><td>data</td>

    </tbody>

    </table>

    <script>

    $('body').on('click',table thead tr input[name="checkall"]',function(){

    if(this.checked){

    $('tbody input[name="checklist"]').prop('checked',$(this).prop('checked'));

    $('tbody tr').addClass('select');

    }else{

    $('tbody input[name="checklist"]').prop('checked',false);

    $('tbody tr').addClass('select');

    }

    });

    $('body').on('click','table tbody tr',function(){

    $(this).toggleClass('select');

    $(this).find('input[name='"checklist"]').prop('checked',$(this).hasClass('select');

    $('#checkall').prop('checked',$('.checklist').length==$('.checklist').filter(":checked").length);

    });

    </script>

    </body>

    </html>

  • 相关阅读:
    JSON的基本认识
    Linux基础 7-10 Bash编程练习4--for循环
    Linux基础7-9 Bash编程--for循环语句
    linux基础 7-3-条件判断语句案例
    Linux基础 7-8 sed命令使用练习
    Linux基础 7-7 set命令的使用
    Linux基础 7-6 Bash脚本编程练习3
    Linux基础7-5 Bash脚本编程--算术运算
    Linux基础7-4 Bash脚本编程练习2
    Linux基础 7-3 Bash脚本编程--条件判断
  • 原文地址:https://www.cnblogs.com/sweeeper/p/6522381.html
Copyright © 2020-2023  润新知