TreeView Checkbox选中
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<script language='javascript' type='text/javascript'>
$(document).ready(function() {
var $checkBox = $(':checkbox');
$checkBox.click(function() {
var value = $(this).attr('checked');
child($(this), value);
parent($(this), value);
});
});
function parent(obj,value) {
var $obj = obj;
var $div = $obj.closest('div');
var $parent = $div.prev('table');
if (!value) {
if ($div.children('table').find(':checkbox:checked').length == 0)
$parent.find(':checkbox').attr('checked', value);
} else {
$parent.find(':checkbox').attr('checked', value);
}
if ($parent.length > 0)
parent($parent, value);
}
function child(obj,value) {
var $obj = obj;
var $table =$obj.closest('table');
var $div =$obj.closest('div');
var $children = $table.next('div');
if ($children.length > 0) {
$children.find(':checkbox').attr('checked', value);
}
}
</script>
$(document).ready(function() {
var $checkBox = $(':checkbox');
$checkBox.click(function() {
var value = $(this).attr('checked');
child($(this), value);
parent($(this), value);
});
});
function parent(obj,value) {
var $obj = obj;
var $div = $obj.closest('div');
var $parent = $div.prev('table');
if (!value) {
if ($div.children('table').find(':checkbox:checked').length == 0)
$parent.find(':checkbox').attr('checked', value);
} else {
$parent.find(':checkbox').attr('checked', value);
}
if ($parent.length > 0)
parent($parent, value);
}
function child(obj,value) {
var $obj = obj;
var $table =$obj.closest('table');
var $div =$obj.closest('div');
var $children = $table.next('div');
if ($children.length > 0) {
$children.find(':checkbox').attr('checked', value);
}
}
</script>
此脚本 很好用 选中父节点 子节点全部选中, 选择子节点 对应的父节点也选中
Treeview1 的属性 ShowCheckBoxes="All"