ajax学习的一点小问题
ajax
在xml文件里我编辑了不少CD便签,如下
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Edited with XML Spy v2007 () --> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> <CD> <TITLE>Unchain my heart</TITLE> <ARTIST>Joe Cocker</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>EMI</COMPANY> <PRICE>8.20</PRICE> <YEAR>1987</YEAR> </CD> </CATALOG>在html里用循环点击表格显示某行详细时显示错误,除非将调用_displayCDInfor()函数里的参数设置为"+i+"才可以正常显示,全部代码如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>ajax</title> </head> <body> <script> if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); }else{ xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } xmlhttp.open('GET','cd_catalog.xml',false); xmlhttp.send(); var xmlDoc = xmlhttp.responseXML; var x = xmlDoc.getElementsByTagName('CD'); function _displayCDInfo(i){ artist=(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue); title=(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); year=(x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue); country=(x[i].getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue); company=(x[i].getElementsByTagName("COMPANY")[0].childNodes[0].nodeValue); price=(x[i].getElementsByTagName("PRICE")[0].childNodes[0].nodeValue); txt="Artist: "+artist+"<br />Title: "+title+"<br />Year: "+year+"<br />Country: "+country+"<br />Company: "+company+"<br />Price: "+price ; document.getElementById("showCD").innerHTML = txt; } </script> <div></div> <script> document.write("<table>"); for(var i=0; i < x.length; i++){ document.write("<tr>"); document.write('<td>'); document.write(x[i].getElementsByTagName('ARTIST')[0].childNodes[0].nodeValue); document.write('</td><td>'); document.write(x[i].getElementsByTagName('TITLE')[0].childNodes[0].nodeValue); document.write('</td></tr>'); } document.write('</table>'); </script> </body> </html>请问为何要将< tr >标签里_dispalyCDInfo()函数的参数设置为"+i+",设置成i反而不正确?