• 用JS读取XML文件


    做一个菜单,需要读取服务器端的XML文件,然后根据XML文件内容拼成菜单.

    读取XML
    var docMenu=new ActiveXObject("Microsoft.XMLDOM"); //创建XmlDom对象
    docMenu.async=true; //使用异步加载
    docMenu.onreadystatechange=LoadedMenu;

    function LoadMenuDoc()
    {
    var Url="Xml/pageMenu.xml";
    docMenu.load(Url);
    }

    function LoadedMenu()
    {
    var txt="<table cellspacing=\"1\" class=\"grid fixed\"><tr><td class=\"category hand\">未加载!</td></tr></table>"
    if(docMenu.readyState==4)
    {
    txt
    = "";
    if(docMenu.parseError.errorCode != 0)
    {
    txt
    ="Error";
    }
    else
    {
    var parents = docMenu.documentElement.selectNodes("ParentMenu");
    if(parents != null && parents.length > 0)
    {
    for(var i=0;i<parents.length;++i)
    {
    if(parents[i].getAttribute("Active") == 0)
    {
    txt
    += "<table cellspacing=\"1\" class=\"grid fixed\"><tr><td class=\"category linkdisable\">≡ { " + parents[i].getAttribute("Name") + " } ≡</td></tr></table><table cellspacing=\"0\"><tr><td colspan=\"3\" style=\"height: 1px;\"><img alt=\"\" src=\"images/blank.gif\" /></td></tr></table>";
    continue;
    }
    else
    {
    txt
    += "<table cellspacing=\"1\" class=\"grid fixed\"><tr><td class=\"category hand\" onclick=\"collapse('menu_"+ i +"')\">≡ { " + parents[i].getAttribute("Name") + " } ≡</td></tr><tr id=\"menu_" + i + "\"><td class=\"items\"><ul>";
    }
    var children = parents[i].childNodes;
    if(children != null && children.length > 0)
    {
    for(var j=0;j<children.length;++j)
    {
    if(children[j].getAttribute("Active") == 0)
    {
    txt
    += "<li class=\"linkdisable\">" + children[j].getAttribute("Name") + "</li>";
    }
    else
    {
    txt
    += "<li><a href=\"" + children[j].getAttribute("Url") + "\">" + children[j].getAttribute("Name") + "</a></li>";
    }
    }
    }
    else
    {
    txt
    += "<li><a href=\"#\"></a></li>";
    }
    txt
    += "</ul></td></tr></table><table cellspacing=\"0\"><tr><td colspan=\"3\" style=\"height: 1px;\"><img alt=\"\" src=\"images/blank.gif\" /></td></tr></table>";
    }
    }
    }
    }
    else
    {
    txt
    ="<table cellspacing=\"1\" class=\"grid fixed\"><tr><td class=\"category hand\">Loading</td></tr></table>";
    }
    leftBar.innerHTML
    = txt;
    }
  • 相关阅读:
    org.tinygroup.ehcache-EhCache缓存解决方案
    org.tinygroup.validate-验证框架
    org.tinygroup.context-上下文环境
    org.tinygroup.commons-常用工具类
    org.tinygroup.context2object-参数对象构建
    org.tinygroup.config-统一应用配置
    org.tinygroup.binarytree-二叉树
    org.tinygroup.service-服务
    flask之wtform与flask-session组件
    Flask信号源码流程
  • 原文地址:https://www.cnblogs.com/KenBlove/p/1339043.html
Copyright © 2020-2023  润新知