首页 >web前端 >js教程 >Javascript 实现TreeView CheckBox全选效果_javascript技巧

Javascript 实现TreeView CheckBox全选效果_javascript技巧

WBOY
WBOY原创
2016-05-16 18:36:42896浏览
复制代码如下代码:

function OnTreeNodeChecked() {
var ele = event.srcElement;
if (ele.type == 'checkbox') {
varchildrenDivID = ele.id.replace('CheckBox', 'Nodes');
var div = document.getElementById(childrenDivID);
if (div != null) {
var checkBoxs = div.getElementsByTagName('INPUT');
for (var i = 0; i if (checkBoxs[i].type == 'checkbox')
checkBoxs[i].checked = ele.checked ;
}
}
OnTreeNodeChildChecked(ele);

}
}
function OnTreeNodeChildChecked(ele) {
//自动处理上级
varparentDiv = ele.parentElement.parentElement.parentElement.parentElement.parentElement;
varparentChkBox = document.getElementById(parentDiv.id.replace('Nodes', 'CheckBox'));
if (parentChkBox != null) {
var ChildsChkAll = true;
var Boxs = ParentDiv.getElementsByTagName('INPUT');
for (var i = 0; i if (Boxs[i].type == 'checkbox' && Boxs[i].checked == false) {
ChildsChkAll = false;
}
}
parentChkBox.checked = ChildsChkAll;
OnTreeNodeChildChecked(parentChkBox);
}
}


CS文件中注册JavaScript:
复制代码 代码如下:

void Page_Load(object sender,EventArgs e)
{
this.TreeView.Attribute.Add("onclick","OnTreeNodeChecked()");
}
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn