通过使用 nodeValue 来改变属性值

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/example/xdom/loadxmldoc.js">
  4. </script>
  5. </head>
  6. <body>
  7.  
  8. <script type="text/javascript">
  9. xmlDoc=loadXMLDoc("/example/xdom/books.xml");
  10.  
  11. x=xmlDoc.getElementsByTagName("book")[0]
  12. y=x.getAttributeNode("category");
  13. y.nodeValue="child";
  14.  
  15. document.write(y.nodeValue);
  16. </script>
  17. </body>
  18. </html>