急求TreeGrid控件用法
我要实现的效果是,第一列是树结构,节点有复选框,点击你节点需要实现子点点选中,其它列表头上都有个全选复选框,点击复选框,此列的每行复选框选中,还有取值也不太懂,有详细代码的可分享下,感激不尽!一定要帮我哦!
[解决办法]
自己摸索一下吧,想当初我也是这样,只可惜我现在也忘记了……
[解决办法]
测试下这个:
<script language="javascript">
function public_GetParentByTagName(element, tagName)
{
var parent = element.parentNode;
var upperTagName = tagName.toUpperCase();
//如果这个元素还不是想要的tag就继续上溯
while (parent && (parent.tagName.toUpperCase() != upperTagName))
{
parent = parent.parentNode ? parent.parentNode : parent.parentElement;
}
return parent;
}
function setParentChecked(objNode)
{
var objParentDiv = public_GetParentByTagName(objNode,"div");
if(objParentDiv==null ¦ ¦ objParentDiv == "undefined")
{
return;
}
var objID = objParentDiv.getAttribute("ID");
objID = objID.substring(0,objID.indexOf("Nodes"));
objID = objID+"CheckBox";
var objParentCheckBox = document.getElementById(objID);
if(objParentCheckBox==null ¦ ¦ objParentCheckBox == "undefined")
{
return;
}
if(objParentCheckBox.tagName!="INPUT" && objParentCheckBox.type == "checkbox")
return;
objParentCheckBox.checked = true;
setParentChecked(objParentCheckBox);
}
function setChildUnChecked(divID)
{
var objchild = divID.children;
var count = objchild.length;
for(var i=0;i <objchild.length;i++)
{
var tempObj = objchild[i];
if(tempObj.tagName=="INPUT" && tempObj.type == "checkbox")
{
tempObj.checked = false;
}
setChildUnChecked(tempObj);
}
}
function setChildChecked(divID)
{
var objchild = divID.children;
var count = objchild.length;
for(var i=0;i <objchild.length;i++)
{
var tempObj = objchild[i];
if(tempObj.tagName=="INPUT" && tempObj.type == "checkbox")
{ tempObj.checked = true;
}
setChildChecked(tempObj);
}
}
function CheckEvent()
{
var objNode = event.srcElement;
if(objNode.tagName!="INPUT" ¦ ¦ objNode.type!="checkbox")
return;
if(objNode.checked==true)
{
setParentChecked(objNode);
var objID = objNode.getAttribute("ID");
var objID = objID.substring(0,objID.indexOf("CheckBox"));
var objParentDiv = document.getElementById(objID+"Nodes");
if(objParentDiv==null ¦ ¦ objParentDiv == "undefined")
{
return;
}
setChildChecked(objParentDiv);
}
else
{
var objID = objNode.getAttribute("ID");
var objID = objID.substring(0,objID.indexOf("CheckBox"));
var objParentDiv = document.getElementById(objID+"Nodes");
if(objParentDiv==null ¦ ¦ objParentDiv == "undefined")
{
return;
}
setChildUnChecked(objParentDiv);
}
}
</script>