jquery实现全选 反选 取消

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="button" value="全选" onclick="checkAll()">
    <input type="button" value="反选" onclick="reserveAll()">
    <input type="button" value="取消" onclick="cancleAll()">
    <table border="1">
        <thread>
            <th>选项</th>
            <th>姓名</th>
            <th>学号</th>
        </thread>
        <tbody>
            <tr>
                <td><input type="checkbox"></td>
                <td>大眼侠</td>
                <td>1001</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>大眼侠</td>
                <td>1001</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>大眼侠</td>
                <td>1001</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>大眼侠</td>
                <td>1001</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>大眼侠</td>
                <td>1001</td>
            </tr>
        </tbody>
    </table>
    <script src="jquery1.9.js"></script>
    <script>

        function checkAll() {
            $(":checkbox").prop("checked",true);
        }
        function  cancleAll() {
            $(":checkbox").prop('checked',false);
        }
        function reserveAll() {
            $(":checkbox").each(function () {
                var v=$(this.checked)? false:true;
                $(this).prop('checked',v);
            })
        }

    </script>
</body>
</html>

 

posted @ 2018-11-07 19:57  大眼侠  阅读(721)  评论(0编辑  收藏  举报