• 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>
  • 相关阅读:
    JSTL笔记(胖先生版)
    EL表达式(胖先生版)
    包装类-Character
    String定义与方法
    冒泡排序(大熊版)
    tomcat Manger App
    第一天
    剑指offer:面试题5、从尾到头打印链表
    剑指offer:面试题4、替换空格
    剑指offer:面试题3、二维数组中的查找
  • 原文地址:https://www.cnblogs.com/zwhbk/p/8680972.html
Copyright © 2020-2023  润新知