zoukankan      html  css  js  c++  java
  • jq实现批量全选与反选

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
    
        <input type="button" value="删除">
        <table border=1>
            <thead>
                <tr>
                    <th><input type="checkbox"></th>
                    <th>2</th>
                    <th>3</th>
                    <th>4</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><input type="checkbox"></td>
                    <td>打两份工</td>
                    <td>真的很高</td>
                    <td><button>删除</button></td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td>打两份工</td>
                    <td>真的很高</td>
                    <td><button>删除</button></td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td>打两份工</td>
                    <td>真的很高</td>
                    <td><button>删除</button></td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td>打两份工</td>
                    <td>真的很高</td>
                    <td><button>删除</button></td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td>打两份工</td>
                    <td>真的很高</td>
                    <td><button>删除</button></td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td>打两份工</td>
                    <td>真的很高</td>
                    <td><button>删除</button></td>
                </tr>
            </tbody>
        </table>
    </body>
    <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
    
    <script>
        $(function(){
            $("input[type=button]").click(function(){
                $("tbody").find("input:checkbox:checked").each(function() { // 遍历选中的checkbox
                    n = $(this).parents("tr").index();  // 获取checkbox所在行的顺序
                    $("tbody").find("tr:eq("+n+")").remove();
                });
            });
        });
        $(function(){
            $("thead").find("input[type=checkbox]").click(function(){
                var flag = $(this).prop("checked"); 
                $("tbody").find("input[type=checkbox]").each(function() { // 遍历选中的checkbox
                    $(this).prop("checked",flag);
                });
            });
        });
    </script>
    
    </html>
  • 相关阅读:
    2016第13周四
    2016第13周周三
    2016第13周二
    2016第13周一
    2016第12周日
    2016第11周五
    2016第11周四
    前端的自我成长
    Java单例模式和volatile关键字
    大约 Apple Metal API 一些想法
  • 原文地址:https://www.cnblogs.com/zwhbk/p/8680972.html
Copyright © 2011-2022 走看看