免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3004 | 回复: 2
打印 上一主题 下一主题

简单的JS treemenu修改 ? 请熟悉JavaScript朋友支招 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-29 17:01 |只看该作者 |倒序浏览
见件是一个例子,网页用frame结构,leftframe调用tree menu 的javascript脚本构造句一个菜单。
我现在每个菜单选项点击时,链接网页显示在leftframe中。

我的目的是,点击每个菜单选项时相应链接的webpage显示在右边的frame中,即显示在mainframe中。
请问如何修改 tree.js 加入 target="mainFrame" ,使之功能实现 ?

tree.js 代码
======================
/**************************************************************************
        Copyright (c) 2001-2003 Geir Landr?(drop@destroydrop.com)
        JavaScript Tree - www.destroydrop.com/hjavascripts/tree/
        Version 0.96       

        This script can be used freely as long as all copyright messages are
        intact.
**************************************************************************/

// Arrays for nodes and icons
var nodes                        = new Array();;
var openNodes        = new Array();
var icons                        = new Array(6);

// Loads all icons that are used in the tree
function preloadIcons() {
        icons[0] = new Image();
        icons[0].src = "img/plus.gif";
        icons[1] = new Image();
        icons[1].src = "img/plusbottom.gif";
        icons[2] = new Image();
        icons[2].src = "img/minus.gif";
        icons[3] = new Image();
        icons[3].src = "img/minusbottom.gif";
        icons[4] = new Image();
        icons[4].src = "img/folder.gif";
        icons[5] = new Image();
        icons[5].src = "img/folderopen.gif";
}
// Create the tree
function createTree(arrName, startNode, openNode) {
        nodes = arrName;
        if (nodes.length > 0) {
                preloadIcons();
                if (startNode == null) startNode = 0;
                if (openNode != 0 || openNode != null) setOpenNodes(openNode);
       
                if (startNode !=0) {
                        var nodeValues = nodes[getArrayId(startNode)].split("|");
                        document.write("<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\"><img src=\"img/folderopen.gif\" align=\"absbottom\" alt=\"\" />" + nodeValues[2] + "</a><br />");
                } else document.write("<img src=\"img/base.gif\" align=\"absbottom\" alt=\"\" />Website<br />");
       
                var recursedNodes = new Array();
                addNode(startNode, recursedNodes);
        }
}
// Returns the position of a node in the array
function getArrayId(node) {
        for (i=0; i<nodes.length; i++) {
                var nodeValues = nodes.split("|");
                if (nodeValues[0]==node) return i;
        }
}
// Puts in array nodes that will be open
function setOpenNodes(openNode) {
        for (i=0; i<nodes.length; i++) {
                var nodeValues = nodes.split("|");
                if (nodeValues[0]==openNode) {
                        openNodes.push(nodeValues[0]);
                        setOpenNodes(nodeValues[1]);
                }
        }
}
// Checks if a node is open
function isNodeOpen(node) {
        for (i=0; i<openNodes.length; i++)
                if (openNodes==node) return true;
        return false;
}
// Checks if a node has any children
function hasChildNode(parentNode) {
        for (i=0; i< nodes.length; i++) {
                var nodeValues = nodes.split("|");
                if (nodeValues[1] == parentNode) return true;
        }
        return false;
}
// Checks if a node is the last sibling
function lastSibling (node, parentNode) {
        var lastChild = 0;
        for (i=0; i< nodes.length; i++) {
                var nodeValues = nodes.split("|");
                if (nodeValues[1] == parentNode)
                        lastChild = nodeValues[0];
        }
        if (lastChild==node) return true;
        return false;
}
// Adds a new node to the tree
function addNode(parentNode, recursedNodes) {
        for (var i = 0; i < nodes.length; i++) {

                var nodeValues = nodes.split("|");
                if (nodeValues[1] == parentNode) {
                       
                        var ls        = lastSibling(nodeValues[0], nodeValues[1]);
                        var hcn        = hasChildNode(nodeValues[0]);
                        var ino = isNodeOpen(nodeValues[0]);

                        // Write out line & empty icons
                        for (g=0; g<recursedNodes.length; g++) {
                                if (recursedNodes[g] == 1) document.write("<img src=\"img/line.gif\" align=\"absbottom\" alt=\"\" />");
                                else  document.write("<img src=\"img/empty.gif\" align=\"absbottom\" alt=\"\" />");
                        }

                        // put in array line & empty icons
                        if (ls) recursedNodes.push(0);
                        else recursedNodes.push(1);

                        // Write out join icons
                        if (hcn) {
                                if (ls) {
                                        document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 1);\"><img id=\"join" + nodeValues[0] + "\" src=\"img/");
                                                 if (ino) document.write("minus");
                                                else document.write("plus");
                                        document.write("bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
                                } else {
                                        document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 0);\"><img id=\"join" + nodeValues[0] + "\" src=\"img/");
                                                if (ino) document.write("minus");
                                                else document.write("plus");
                                        document.write(".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
                                }
                        } else {
                                if (ls) document.write("<img src=\"img/joinbottom.gif\" align=\"absbottom\" alt=\"\" />");
                                else document.write("<img src=\"img/join.gif\" align=\"absbottom\" alt=\"\" />");
                        }

                        // Start link
                        document.write("<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
                       
                        // Write out folder & page icons
                        if (hcn) {
                                document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/folder")
                                        if (ino) document.write("open");
                                document.write(".gif\" align=\"absbottom\" alt=\"Folder\" />");
                        } else document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/page.gif\" align=\"absbottom\" alt=\"Page\" />");
                       
                        // Write out node name
                        document.write(nodeValues[2]);

                        // End link
                        document.write("</a><br />");
                       
                        // If node has children write out divs and go deeper
                        if (hcn) {
                                document.write("<div id=\"div" + nodeValues[0] + "\"");
                                        if (!ino) document.write(" style=\"display: none;\"");
                                document.write(">");
                                addNode(nodeValues[0], recursedNodes);
                                document.write("</div>");
                        }
                       
                        // remove last line or empty icon
                        recursedNodes.pop();
                }
        }
}
// Opens or closes a node
function oc(node, bottom) {
        var theDiv = document.getElementById("div" + node);
        var theJoin        = document.getElementById("join" + node);
        var theIcon = document.getElementById("icon" + node);
       
        if (theDiv.style.display == 'none') {
                if (bottom==1) theJoin.src = icons[3].src;
                else theJoin.src = icons[2].src;
                theIcon.src = icons[5].src;
                theDiv.style.display = '';
        } else {
                if (bottom==1) theJoin.src = icons[1].src;
                else theJoin.src = icons[0].src;
                theIcon.src = icons[4].src;
                theDiv.style.display = 'none';
        }
}
// Push and pop not implemented in IE
if(!Array.prototype.push) {
        function array_push() {
                for(var i=0;i<arguments.length;i++)
                        this[this.length]=arguments;
                return this.length;
        }
        Array.prototype.push = array_push;
}
if(!Array.prototype.pop) {
        function array_pop(){
                lastElement = this[this.length-1];
                this.length = Math.max(this.length-1,0);
                return lastElement;
        }
        Array.prototype.pop = array_pop;
}
===============================

treedemo.zip

15.89 KB, 下载次数: 155

论坛徽章:
0
2 [报告]
发表于 2006-09-30 12:54 |只看该作者
看附件中的例子

dtree.zip

14.61 KB, 下载次数: 185

论坛徽章:
0
3 [报告]
发表于 2006-10-04 15:42 |只看该作者
谢谢 !搞清楚啦 !
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP