1. [代码] [XML]代码 ?xml version="1.0" encoding="UTF-8"?detailsnamezqwang121/namewebsitehttp://zqwang.cc//websiteemailzqwang121@sina.com/email/details 2. [代码] [HTML]代码 bodyh1People/h1ullia href="1.html"1/a/lilia href="2.html"2/a
1. [代码][XML]代码
<?xml version="1.0" encoding="UTF-8"?> <details> <name>zqwang121</name> <website>http://zqwang.cc/</website> <email>zqwang121@sina.com</email> </details>
2. [代码][HTML]代码
<body> <h1>People</h1> <ul> <li><a href="1.html">1</a></li> <li><a href="2.html">2</a></li> <li><a href="3.html">3</a></li> </ul> <div id="zqwang121"></div> </body>
3. [代码][JavaScript]代码
<script type="text/javascript"> window.onload=function(){ var aNodes=document.getElementsByTagName("a"); for(var i=0;i<aNodes.length;i++){ aNodes[i].onclick=function(){ var request=new XMLHttpRequest(); var method="GET"; var url=this.href; request.open(method,url); request.send(null); request.onreadystatechange=function(){ if(request.readyState==4){ if(request.status==200){ //1.结果为xml格式,所以需要使用responsexml来获取 var result=request.responseXML; //2.结果不能直接使用,必须先创建对应的节点,再把节点加入到zqwang121里面 //目标格式为 /* <h2><a href="zqwang121@sina.com">zqwang121</a></h2> <a href="http://zqwang.cc">http://zqwang.cc</a> */ var name=result.getElementsByTagName("name")[0].firstChild.nodeValue; var website=result.getElementsByTagName("website")[0].firstChild.nodeValue; var email=result.getElementsByTagName("email")[0].firstChild.nodeValue; //alert(name); //alert(website); //alert(email); var aNode=document.createElement("a"); aNode.appendChild(document.createTextNode(name)); aNode.href="mailto:"+email; var h2Node=document.createElement("h2"); h2Node.appendChild(aNode); var aNode2=document.createElement("a"); aNode2.appendChild(document.createTextNode(website)); aNode2.href=website; var zqwang121Node=document.getElementById("zqwang121"); zqwang121Node.innerHTML=""; zqwang121Node.appendChild(h2Node); zqwang121Node.appendChild(aNode2); } } } return false; } } } </script>