当前位置: 首页 > 图文教程 > 网络编程 > Javascript > TreeView节点互斥,autopostback=false的方法

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 TreeView节点互斥,autopostback=false的方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 419 ::
收藏到网摘: n/a

 

问题描述:frameset中的TreeView,里面就四个节点,想打开一个后,关闭其它三个节点。
开始是在TreeView1_Expand里写,倒也能用,可要设置autopostback为true,刷新时很难看,就在网上找资料
相关主题如下:
==================
1. "展开时不提交,改变选择节点时才提交"
2. "使TreeView展开一个节点后自动缩回其他所有的已经展开的节点,就是说同一时间内只有一个展开节点"
3. "TreeView展开无闪烁的解决方法"
4. "TreeView专题讨论" 
5. "TreeView JavaScript控制方法研究"
==================
上面有个javascript角本写的不错,可试了半天老是出错。
于是自已写了一个。


<script  language="JavaScript"> 
  function  initTree()
  { 
    var tree = document.all["TreeView1"];
    tree.attachEvent("onexpand", SelectedIndexChange); //追加个事件
  }
  function SelectedIndexChange()
  {
    var temp = this.TreeView1.clickedNodeIndex;
    var nodes = new Array();
    nodes = this.TreeView1.getChildren();
    for(i=0;i<nodes.length;i++)
    {
      if(i!=temp)
      {
        if(i<10)
   nodeIndex = "0"+i;//我这只用到了四个节点的,十个以上的自已试试看吧。
 this.TreeView1.getTreeNode(nodeIndex).setAttribute('expanded','false');
      }
    }
}
</script>
最后在body里写一个
<body onload="initTree();">
就可以用了。

当然也可以像"TreeView专题讨论"中把javascript写在page_load里,不过那样就很麻烦了,也很容易出错儿。