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>
  • 相关阅读:
    Windows下的RabbitMQ安装:RabbitMQ_Service安装
    [Java]private, public,protected,friendly的区别(转载)一下子就记住了
    mysql的一些sql用法
    set(string str)变量传参为int的问题
    eclipse插件开发常见的问题及解决办法
    eclipse 内存溢出
    如何在一台机器上运行2个Tomcat
    eclipse svn使用
    eclipse遇到的异常
    oracle学习
  • 原文地址:https://www.cnblogs.com/zwhbk/p/8680972.html
Copyright © 2011-2022 走看看