简单教程
提交运行
代码编辑器:
<!DOCTYPE html> <html> <body> <script> if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } xmlhttp.open("GET","/static/media/books.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; x=xmlDoc.getElementsByTagName("book"); for(i=0;i<x.length;i++) { x[i].setAttribute("edition","first"); } for (i=0;i<x.length;i++) { document.write("Category: " + x[i].getAttribute('category') + "<br>"); document.write("Edition: " + x[i].getAttribute('edition') + "<br>"); } </script> </body> </html>
运行结果: