js实现权限树的更新权限时的全选全消功能
人气:0复制代码 代码如下:
// JScript 文件
function getParentByTagName(element,tagName)
{
var parent = element.parentNode;
var upperTagName = tagName.toUpperCase();
while (parent && (parent.tagName.toUpperCase() != upperTagName))
{
parent = parent.parentNode ? parent.parentNode : parent.parentElement;
}
return parent;
}
function setParentChecked(objNode)
{
var objParentDiv = getParentByTagName(objNode,"div");
if(objParentDiv == null || objParentDiv == "undefined")
return;
var objID = objParentDiv.getAttribute("ID");
var objParentCheckBox = document.getElementById(objID.replace("Nodes","CheckBox"));
if(objParentCheckBox == null || objParentCheckBox == "undefined")
return;
if(objParentCheckBox.tagName!="INPUT" && objParentCheckBox.type == "checkbox")
return;
//add
// if (objNode.checked=false) objPraentCheckBox.checked=false;
// objParentCheckBox.checked = true;
setParentChecked(objParentCheckBox);
}
function setParentUnChecked(objNode)
{
var objParentDiv = getParentByTagName(objNode,"div");
if(objParentDiv == null || objParentDiv == "undefined")
return;
var objID = objParentDiv.getAttribute("ID");
var objParentCheckBox = document.getElementById(objID.replace("Nodes","CheckBox"));
if(objParentCheckBox == null || objParentCheckBox == "undefined")
return;
if(objParentCheckBox.tagName!="INPUT" && objParentCheckBox.type == "checkbox")
return;
//add
// if (objNode.checked=false) objPraentCheckBox.checked=false;
objParentCheckBox.checked = false;
setParentUnChecked(objParentCheckBox);
}
function setChildCheckedState(div,state)
{
var objchild = div.childNodes;
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 = state;
}
// debugger;
setChildCheckedState(tempObj,state);
}
}
function TreeNodeChecked()
{
var objNode = window.event.srcElement;
if(objNode.tagName!="INPUT" || objNode.type!="checkbox")
return;
// debugger;
if(objNode.checked == true)
{
setParentChecked(objNode);
}
else
{
setParentUnChecked(objNode);
}
var objID = objNode.getAttribute("ID");
var objParentDiv = document.getElementById(objID.replace("CheckBox","Nodes"));
if(objParentDiv==null || typeof(objParentDiv) == "undefined")
return;
setChildCheckedState(objParentDiv,objNode.checked);
}
function SetTreeNodeChecked(objNode1)
{
var objNode =objNode1;
var objID = objNode.getAttribute("ID");
var objParentDiv = document.getElementById(objID.replace("CheckBox","Nodes"));
if(objParentDiv==null || typeof(objParentDiv) == "undefined")
return;
setChildCheckedState(objParentDiv,objNode.checked);
}
function GetYHQS(id)
{
PageMethods.CallYHQX(id,callsuccessed);
}
function callsuccessed(result)
{
// //循环页面
/https://img.qb5200.com/download-x/debugger;
for (i=0;i<document.form1.length ;i++)
{
var objNode=document.form1.elements[i];
if (objNode.tagName=="INPUT" && objNode.type=="checkbox")
{
objNode.checked=false;
}
}
for (i=0;i<document.form1.length ;i++)
{
var objNode=document.form1.elements[i];
if (objNode.tagName=="INPUT" && objNode.type=="checkbox")
{
//找到
//比较
if (result.indexOf(objNode.title)!=-1)
{
objNode.checked=true;
SetTreeNodeChecked(objNode);
}
}
}
}
function test()
{
debugger;
//循环页面
for (i=0;i<document.form1.length ;i++)
{
var objNode=document.form1.elements[i];
if (objNode.tagName=="INPUT" && objNode.type=="checkbox")
{
//找到
//比较
objNode.checked=true;
}
}
}
加载全部内容