能帮我看看这段XML+HTML小程序有什么问题吗?这个程序实现了鼠标点击一行后,显示该行的详细信息。但是我点击一行后,总是显示第一行的信息,其他行无法显示。
这个是HTML代码,文件名Breakfast_menu.html:
------------
这个是XML代码,文件名Breakfast_menu.xml:
<!DOCTYPE html>
<html>
<head>
<title>获取XML文件的某个节点下的某些元素</title>
<meta charset="UTF-8">
<script>
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "Breakfast_menu.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
x = xmlDoc.getElementsByTagName("food");// x忘记写过
function displayFood(i) {
name = (x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
price = (x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
description = (x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue);
calories = (x[i].getElementsByTagName("calories")[0].childNodes[0].nodeValue);
txt = "i:" + i + "<br/>Name:" + name + "<br/>Price:" + price +
"<br/>Description:" + description + "<br/>Calories:" + calories;
document.getElementById("showFood").innerHTML = txt;// 是getElementById(),不是getElementsById()。没有s。
}
</script>
</head>
<body>
<div id="showFood">Click on a Food to display album information.</div>
<hr>
<script>
document.write("<table border='1'");
// 遍历每一个food
for (var i = 0; i < x.length; i++) {
document.write("<tr onclick= displayFood(" + i + ")>");
document.write("<td>");
document.write(i);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
document.write("params.length:" + x.length);
</script>
</body>
</html>
------------
这个是XML代码,文件名Breakfast_menu.xml:
<?xml version="1.0" encoding="UTF-8"?><!-- 也可以是ISO-8859-1编码 -->
<!-- 该xml引用外部css样式 -->
<!-- <?xml-stylesheet type="text/css" href="./Breakfast_menu.css"?> -->
<!-- 该xml引用外部学生类样式 -->
<?xml-stylesheet type="text/xsl" href="./Breakfast_menu.xsl"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real
maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and
whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh
berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread
</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular
hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
...全文
相关推荐
ajax小例子 鼠标移动菜单 显示详细信息
ajax小例子 鼠标移动菜单 显示详细信息
Flash+xml+js鼠标点击查看大图
Flash+xml+js鼠标点击查看大图
不允许点击鼠标右键,不能ctrl+a,不能复制粘贴的代码
实际项目中,为了防止用户看到或者复制代码,可以进行简单操作紧闭普通用户的实际需求,当然直接在查看里查看源文件还是不行的,要想真正紧闭,还是的用ajax。这个只是初级的紧闭
鼠标悬停读取详细信息
鼠标悬停读取详细信息 鼠标悬停读取详细信息
CSS鼠标响应事件经过、移动、点击示例介绍
本文为大家介绍下CSS 鼠标响应事件:鼠标经过CSS、鼠标移动CSS、鼠标点击CSS以及示例,喜欢的朋友可以参考下


