陪你做好前端设计!
源代码:
点击运行
<!DOCTYPE html> <html> <body> <h1>W3Cschool Internal Note</h1> <div> <b>To:</b> <span id="to"></span><br> <b>From:</b> <span id="from"></span><br> <b>Message:</b> <span id="message"></span> </div> <script> txt="<note>"; txt=txt+"<to>Tove</to>"; txt=txt+"<from>Jani</from>"; txt=txt+"<heading>Reminder</heading>"; txt=txt+"<body>Don't forget me this weekend!</body>"; txt=txt+"</note>"; if (window.DOMParser) { parser=new DOMParser(); xmlDoc=parser.parseFromString(txt,"text/xml"); } else // Internet Explorer { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.loadXML(txt); } document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue; document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue; document.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue; </script> </body> </html>
运行结果