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教程 117 4年前
  • Jquery实战视频教程 6小时精通Jq
    Jquery实战视频教程 6小时精通Jq

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

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

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

    js教程 72 3年前
最新更新
  • js截取字符串教程

    slice()方法接受两个参数,起始索引和结束索引(可选)。它返回从起始索引到结束索引(不包括结束索引)之间的子字符...

    js教程 1个月前
  • find findIndex indexOf索引选择器使用方法

    find使用方法find方法是ES6引入的一种数组方法,可以用来查找数组中符合条件的元素。语法是:array.find(callba...

    js教程 2个月前
  • js复制网页内容教程

    Async Clipboard API方法HTML5新增的方法,无需引入第三方插件,直接就可以复制内容。低版本的浏览器可能会不兼...

    js教程 2个月前
  • js获取字符长度函数分享

    js获取字符长度函数function objLen(str) { if (str == null) return 0; if (typeof str != "string") { ...

    js教程 2个月前
  • 网站LED跑马灯效果广告代码

    网站可以看到很多的论坛网站都会用到这种网站LED跑马灯效果,这种效果实现也很简单,分享给大家。LED跑马灯效果...

    js教程 3个月前