运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,暗/亮
前往 Spaces
<!DOCTYPE html> <html> <body> <div id='showCD'></div><br> <input type="button" onclick="previous()" value="<<"> <input type="button" onclick="next()" value=">>"> <script> let i = 0; let len; let cd; const xhttp = new XMLHttpRequest(); xhttp.onload = function() { const xmlDoc = xhttp.responseXML; cd = xmlDoc.getElementsByTagName("CD"); len = cd.length; displayCD(i); } xhttp.open("GET", "cd_catalog.xml"); xhttp.send(); function displayCD(i) { document.getElementById("showCD").innerHTML = "Artist: " + cd[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue + "<br>Title: " + cd[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue + "<br>Year: " + cd[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue; } function next() { if (i < len-1) { i++; displayCD(i); } } function previous() { if (i > 0) { i--; displayCD(i); } } </script> </body> </html>