Treeview 只展开一个节点 其他兄弟节点关闭


Treeview 只展开一个节点 其他兄弟节点关闭,记录一下方便以后使用

重写系统自动生成的TreeView_ToggleNode函数。

用记事本打开页面源代码,可以找到一下两个脚本引用:里面包含系统自动生成的TreeView_ToggleNode函数

<script src="/Web/WebResource.axd?d=RAQeBcDUNuP9iuS8q3tNEw2&amp;t=633300220640000000" type="text/javascript"></script>
 <script src="/Web/WebResource.axd?d=JuTdJhq3NM8Jq_RhssAkEg2&amp;t=633300220640000000" type="text/javascript"></script>



function TreeView_ToggleNode(data, index, node, lineType, children) {
if (!data) {
return;
}
var img = node.childNodes[0];
var newExpandState;
try {
CollapseBrothers(data, lineType, children);
if (children.style.display == "none") {
children.style.display = "block";
newExpandState = "e";
if ((typeof (img) != "undefined") && (img != null)) {
if (lineType == "l") {
img.src = data.images[15];
}
else if (lineType == "t") {
img.src = data.images[12];
}
else if (lineType == "-") {
img.src = data.images[18];
}
else {
img.src = data.images[5];
}
img.alt = data.collapseToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));
}
}
else {
children.style.display = "none";
newExpandState = "c";
if ((typeof (img) != "undefined") && (img != null)) {
if (lineType == "l") {
img.src = data.images[14];
}
else if (lineType == "t") {
img.src = data.images[11];
}
else if (lineType == "-") {
img.src = data.images[17];
}
else {
img.src = data.images[4];
}
img.alt = data.expandToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));
}
}
}
catch (e) { }
data.expandState.value = data.expandState.value.substring(0, index) + newExpandState + data.expandState.value.slice(index + 1);
}

//折叠兄弟节点(Collapse Brothers)
function CollapseBrothers(data, lineType, children) {

var PreNode = PreviousSibling(children);
var IsFist = false;
while (PreNode != null) {
if (PreNode.tagName.toLowerCase() == "table" && IsFist) {
var IsClose = true;//判断此节点是否为关闭状态
var img = PreNode.getElementsByTagName("IMG")[0];
if (lineType == "l") {
if (0 <= img.src.indexOf(data.images[15])) {
img.src = data.images[14];
IsClose = false;
}
}
else if (lineType == "t") {
if (0 <= img.src.indexOf(data.images[12])) {
img.src = data.images[11];
IsClose = false;
}
}
else if (lineType == "-") {
if (0 <= img.src.indexOf(data.images[18])) {
img.src = data.images[17];
IsClose = false;
}
}
else {
if (0 <= img.src.indexOf(data.images[5])) {
img.src = data.images[4];
IsClose = false;
}
}

if(!IsClose)
{
img.alt = data.expandToolTip.replace(/\{0\}/, TreeView_GetNodeText(PreNode.getElementsByTagName("a")[0]));
var aid = PreNode.getElementsByTagName("a")[0].id;
var index = aid.substring(aid.lastIndexOf("n") + 1, aid.length);
var newExpandState = "c";
//设置回发时的状态
data.expandState.value = data.expandState.value.substring(0, index) + newExpandState + data.expandState.value.slice(index + 1);
}
}
else if (PreNode.tagName.toLowerCase() == "table") {
IsFist = true;
}
else if (PreNode.tagName.toLowerCase() == "div") {
PreNode.style.display = "none";
}
PreNode = PreviousSibling(PreNode);

}

PreNode = NextSibling(children);
while (PreNode != null) {
if (PreNode.tagName.toLowerCase() == "table") {
var IsClose = true; //判断此节点是否为关闭状态
var img = PreNode.getElementsByTagName("IMG")[0];
if (lineType == "l") {
if (0 <= img.src.indexOf(data.images[15])) {
img.src = data.images[14];
IsClose = false;
}
}
else if (lineType == "t") {
if (0 <= img.src.indexOf(data.images[12])) {
img.src = data.images[11];
IsClose = false;
}
}
else if (lineType == "-") {
if (0 <= img.src.indexOf(data.images[18])) {
img.src = data.images[17];
IsClose = false;
}
}
else {
if (0 <= img.src.indexOf(data.images[5])) {
img.src = data.images[4];
IsClose = false;
}
}

if (!IsClose) {
img.alt = data.expandToolTip.replace(/\{0\}/, TreeView_GetNodeText(PreNode.getElementsByTagName("a")[0]));
var aid = PreNode.getElementsByTagName("a")[0].id;
var index = aid.substring(aid.lastIndexOf("n") + 1, aid.length);
var newExpandState = "c";
//设置回发时的状态
data.expandState.value = data.expandState.value.substring(0, index) + newExpandState + data.expandState.value.slice(index + 1);
}
}
else if (PreNode.tagName.toLowerCase() == "div") {
PreNode.style.display = "none";
}
PreNode = NextSibling(PreNode);
}
}


//取下一个同级节点,没有返回null,兼容ie、ff
function NextSibling(e) {
var nextE = e.nextSibling;
while (nextE != null && nextE.nodeType != "1") {
nextE = nextE.nextSibling;
}
return nextE;
}
//取上一个同级节点,没有返回null,兼容ie、ff
function PreviousSibling(e) {
var preE = e.previousSibling;
while (preE != null && preE.nodeType != "1") {
preE = preE.previousSibling;
}
return preE;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值