首頁  >  文章  >  web前端  >  js实现权限树的更新权限时的全选全消功能_javascript技巧

js实现权限树的更新权限时的全选全消功能_javascript技巧

WBOY
WBOY原創
2016-05-16 18:56:01866瀏覽

复制代码 代码如下:

// 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{
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)
{
// //循环页面
//debugger;
for (i=0;i{
var objNode=document.form1.elements[i];
if (objNode.tagName=="INPUT" && objNode.type=="checkbox")
{
objNode.checked=false;
}
}
for (i=0;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{
var objNode=document.form1.elements[i];
if (objNode.tagName=="INPUT" && objNode.type=="checkbox")
{
//找到
//比较
objNode.checked=true;
}
}
}
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn