16-8.htm

来自「《JAVASCRIPT 动态网页编程实例手册》一书中的源代码」· HTM 代码 · 共 35 行

HTM
35
字号
    <html><head><title>访问XML元素</title> 
        <xml ID="xml1" SRC="16-2.xml"></xml> 
        <script language="javascript"> 
        <!--
            function readXMLDocument() 
            { 
              var document1, eventsNode, eventNode, peopleNode; 
              var nameNode, titleNode, displayText ;
              var attributes, attendencePerson  ;
              document1= document.all("xml1").XMLDocument; 
              eventsNode = document1.documentElement; 
              eventNode = eventsNode.firstChild; 
              peopleNode = eventNode.lastChild; 
              personNode = peopleNode.lastChild; 
              nameNode = personNode.firstChild; 
              titleNode = nameNode.nextSibling; 
              attributes = personNode.attributes; 
              attendencePerson = attributes.getNamedItem("ATTENDENCE"); 
              displayText = nameNode.firstChild.nodeValue 
                      + ' ' + titleNode.firstChild.nodeValue 
                      + " 为 " + attendencePerson.value; 
              div1.innerHTML=displayText; 
             } 
         //--> 
         </script> 
    </head> 
    <body> 
        <h1>访问XML元素</h1> 
        <input type="button" value="得到第三位客人的名字、职位与类别" 
            onclick="readXMLDocument()"> 
        <br> <br>
        <div id="div1"></div> 
    </body> 
    </html> 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?