码迷,mamicode.com
首页 > Web开发 > 详细

Jquery - checked 全选与取消全选

时间:2016-02-12 17:30:26      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

html:

<!DOCTYPE html>
<html>
<head>
    <title>节点列表</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/Public.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/node.css">
    <script type="text/javascript" src="__PUBLIC__/Js/jquery.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Js/node.js"></script>
</head>
<body>
    <div id="wrap">
        <div>
            <a href="<{:U(‘/Admin/Rbac/role‘)}>" class="add-app">返回</a>
        </div>
        <div>
            <foreach name="node" item="app">
                <div class="app">
                    <p>
                        <strong><{$app.title}></strong>
                        <input type="checkbox" name="access[]"  value="<{$app.id}>_1" level=‘1‘ />
                    </p>

                    <foreach name="app.child" item="action">
                        <dl>
                            <dt>
                                <strong><{$action.title}></strong>
                                <input type="checkbox" name="access[]" value="<{$action.id}>_3" level=‘2‘  />
                            </dt>

                            <foreach name="action.child" item="func">
                                <dd>
                                    <span><{$func.title}></span>
                                    <input type="checkbox" name="access[]" value="<{$func.id}>_3" level=‘3‘  />
                                </dd>
                            </foreach>
                        </dl>
                    </foreach>
                </div>
            </foreach>
        </div>
    </div>
</body>
</html>

 

JS:

$(document).ready(function(){
    $(‘input[level="1"]‘).click(function() {            
        var inputs = $(this).parents(‘.app‘).find(‘input‘);
        $(this).prop(‘checked‘) ? inputs.prop(‘checked‘, true) : inputs.removeAttr(‘checked‘, false);
    });

    $(‘input[level="2"]‘).click(function() {
        var inputs = $(this).parents(‘dl‘).find(‘input‘);
        $(this).prop(‘checked‘) ? inputs.prop(‘checked‘, true) : inputs.removeAttr(‘checked‘, false);
    });
});

 

Jquery - checked 全选与取消全选

标签:

原文地址:http://www.cnblogs.com/KTblog/p/5187120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!