zoukankan      html  css  js  c++  java
  • js操作dom(2)

    <script type="text/javascript" src="sg_share.js"></script>
    <script type="text/javascript">
        
    var xml=sg.xmlDocument();
        xml.load(
    "XmlFeedbackTemplate.xml");
        
    var ColumnsNode=xml.selectSingleNode("Schema/Summary/Columns");
        
    for(var i=0,j=ColumnsNode.childNodes.length;i<j;i++)
        
    {
            
    //以下两者皆可
            //alert(ColumnsNode.childNodes[i].attributes[0].value);
            alert(ColumnsNode.childNodes[i].getAttribute("ColumnName"));
        }

    </script>

    <?xml version="1.0" encoding="utf-8" ?>
    <Schema>
      
    <Summary>
        
    <Columns>
          
    <Column ColumnName="IndexId" Width="0px"  index="0"/>
          
    <Column ColumnName="IsIndex" Width="0px"  index="1"/>
          
    <Column ColumnName="Lever" Width="0px"  index="2"/>
          
    <Column ColumnName="intOptionID" Width="0px"  index="2"/>
          
    <Column ColumnName="intDimensionID" Width="0px"  index="2"/>
          
    <Column ColumnName="指标名称" Width="100px"  index="3"/>
          
    <Column ColumnName="指标说明" Width="150px" index="4"/>
          
    <Column ColumnName="权重" Width="80px"  index="5"/>
          
    <Column ColumnName="单位" Width="80px" index="6"/>
          
    <Column ColumnName="指标属性" Width="150px" index="7" />
          
    <Column ColumnName="是否考核" Width="150px" index="8"/>
          
    <Column ColumnName="minScore" Width="150px" index="10"/>
          
    <Column ColumnName="maxScore" Width="150px" index="11"/>
          
    <Column ColumnName="defaultScore" Width="150px" index="12"/>
        
    </Columns>
      
    </Summary>
      
    <Rows>
      
    </Rows>
    </Schema>

    关于sg_share.js的代码可以参考我上一篇关于js操作xml的文章。
    js加载xml文件,其实可以写个通用的库,参考我javascript分类里面关于xmldom的代码
    注意以下几点:
    1)加载xml文件,用load,加载包含xml字符串用loadXML;
    2)childNodes是集合,引用其中元素用childNodes[i];
    3)节点有attributes属性的集合,引用其中元素用attributes[i];
    4)而getAttribute和setAttribute是方法,可以传入节点名称做为参数,getAttribute(attributeName),莫要用[],小心不留心搞错了。
  • 相关阅读:
    采购订单打印并预览PDF
    KiCad 如何在原理图添加元件时看到 PCB 封装?
    KiCad 开源元件库收集 (2019-05-31)
    KiCad 的 Digikey 元件库
    MySQL 出现 Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
    AD10 没有原理图是否可以修改 PCB
    KiCad 如何画板框
    当 1117 遇到 MLCC 后
    RequireJS 学习资料收集
    MEMS 硅麦资料收集
  • 原文地址:https://www.cnblogs.com/jackhuclan/p/1175976.html
Copyright © 2011-2022 走看看