js教程

jquery批量全选和反选教程

我的站长站 2023-03-13 人阅读
<!DOCTYPE html>
<html>
<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>


相关推荐
  • jquery教程
  • jQuery获取file控件中图片的宽高与大小

    jQuery获取file宽高的代码如下,仅在火狐中测试了,其他浏览器兼容性未知。var _URL = window.URL || window.webkitURL;$("#file").change(function (e) { var file, img; if ((file = this.files[0])) { img = new Image(); img.onload = func...

    js教程 125 5年前
  • Jquery实战视频教程 6小时精通Jq
    Jquery实战视频教程 6小时精通Jq

    Jquery实战视频教程 6小时精通Jq,实现小应用,附带教程源码。视频教程列表第7章 自动以Alert第6章 标记完成状态、定时提醒第5章 Task详情第4章 添加及查看Task第3章 细节完善第2章 整体布局第1章 ...

    视频教程 116 4年前
  • JQuery鼠标移动添加删除样式

    JQuery鼠标移动添加删除样式方法,下面为代码案列$("a").hover(function(){ $(this).find("b").show();},function(){ $(this).find("b").hide();})鼠标移到A标签触发事件,下面的B标签显示,后门的function就是鼠标移开隐藏。...

    js教程 89 3年前
最新更新