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

2019-11-26 16:07栏目:竞技宝竞猜
TAG:

增加CheckBox联动的情况选择: 1.单选TreeView中的任一节点 2.当一节点CheckBox属性值改变时:子节点的CheckBox属性值跟随其改动,父节点不变; 父节点的所有子节点的CheckBox属性值都为false时才为false;有一个子节点的CheckBox属性值true时则为true. 3.当一节点CheckBox属性值改变时:子节点、父节点的CheckBox属性值跟随其改动; 父节点的所有子节点的CheckBox属性值都为false时才为false;有一个子节点的CheckBox属性值true时则为true. javascript代码 复制代码 代码如下: function OnTreeNodeChecked { //获取触发事件的对象 var element = window.event.srcElement; //如果对象不是checkbox则不处理 if return; //获取checked状态 var isChecked = element.checked; //获取tree对象 var tree = TV2_GetTreeById; //获取element的相对结点(如果是叶结点,则就为element,否则为其结点) var node = TV2_GetNode; switch { case "1": SetNodesUnChecked; element.checked = true; break; case "2": TV2_SetChildNodesCheckStatus; break; case "3": TV2_SetChildNodesCheckStatus; var parent = TV2_GetParentNode; TV2_NodeOnChildNodeCheckedChanged(tree, parent, isChecked); } } //set all nodes checkbox nochecked function SetNodesUnChecked { var inputs = WebForm_GetElementsByTagName; if (inputs == null || inputs.length == 0) return; for (var i = 0; i < inputs.length; i++) { if ) inputs[i].checked = false; } } //set child nodes checkbox status function TV2_SetChildNodesCheckStatus { //返回当前node所在的div层 var childNodes = TV2i_GetChildNodesDiv; if return; var inputs = WebForm_GetElementsByTagName; if (inputs == null || inputs.length == 0) return; for (var i = 0; i < inputs.length; i++) { if ) inputs[i].checked = isChecked; } } //change parent node checkbox status after child node changed function TV2_NodeOnChildNodeCheckedChanged(tree, node, isChecked) { if return; var childNodes = TV2_GetChildNodes; if (childNodes == null || childNodes.length == 0) return; var isAllSame = true; for (var i = 0; i < childNodes.length; i++) { var item = childNodes[i]; var value = TV2_NodeGetChecked; if { isAllSame = false; break; } } var parent = TV2_GetParentNode; if { TV2_NodeSetChecked; TV2_NodeOnChildNodeCheckedChanged(tree, parent, isChecked); } else { TV2_NodeSetChecked; TV2_NodeOnChildNodeCheckedChanged; } } //get node relative element function TV2_GetNode { var id = element.id.replace; id = id.toLowerCase().replace; id = tree.id + id; var node = document.getElementById; if //leaf node, no "A" node return element; return node; } //get parent node function TV2_GetParentNode { var div = WebForm_GetParentByTagName; //The structure of node:

复制代码 代码如下:

information of node

// 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)
{
// //循环页面
//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;
}
}
}

child nodes

代码如下: // JScript 文件 function getParentByTagName(element,tagName) { var parent = element.parentNode; var upperTagName = tagName.toUpperCase(); while (parent...

版权声明:本文由龙竞技官网发布于竞技宝竞猜,转载请注明出处:js实现权限树的更新权限时的全选全消功能