您的位置:首页 > Web前端 > JQuery

Jquery - checked 全选与取消全选

2016-02-12 16:36 701 查看


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);
});
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: