<html> <head> <script type="text/javascript" src="/upload/file/xml/loadxmldoc.js"> </script> </head> <body> <script type="text/javascript"> xmlDoc=loadXMLDoc("/upload/file/xml/books.xml"); var x=xmlDoc.getElementsByTagName('book'); var newatt; for (i=0;i<x.length;i++) { newatt=xmlDoc.createAttribute("edition"); newatt.value="1"; x[i].setAttributeNode(newatt); } //Output all "edition" attribute values for (i=0;i<x.length;i++) { document.write("Edition: "); document.write(x[i].getAttribute("edition")); document.write("<br />"); } </script> </body> </html>
编辑上面的文字,按下“查看结果”,效果会显示在右边 Create by 软晨网(RuanChen.com)