需要以下JavaScript函数的帮助。
当我把每一个分开时,好像它们是分开的功能一样 (即一次只注意一个)。 我确实得到了预期值。
但是当作为代码块运行时,只会提醒第一个值。 无法看到我做错了什么
function stateChanged(){
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
if (xmlhttp.readyState==4){
var product = document.getElementById ("product");
for (var i = 0; i < product.childNodes.length; i++) {
var child = product.childNodes[i];
if (child.nodeType == 3) {
//alert ("The " + i + ". child is a text node. Contents:\n" + child.data);
var customerProduct = product.childNodes[i].nodeValue;
alert(customerProduct);
}
else {
if (child.nodeType == 1) {
var product = ("The " + i + ". child is an element node. Contents:\n" + child.innerHTML);
}
}
}
var model = document.getElementById ("model");
for (var i = 0; i < model.childNodes.length; i++) {
var child = model.childNodes[i];
if (child.nodeType == 3) {
//alert ("The " + i + ". child is a text node. Contents:\n" + child.data);
var productModel = model.childNodes[i].nodeValue;
alert(productModel);
}
else {
if (child.nodeType == 1) {
var model = ("The " + i + ". child is an element node. Contents:\n" + child.innerHTML);
}
}
}
var serial = document.getElementById ("serial");
for (var i = 0; i < serial.childNodes.length; i++) {
var child = serial.childNodes[i];
if (child.nodeType == 3) {
//alert ("The " + i + ". child is a text node. Contents:\n" + child.data);
var productSerial = serial.childNodes[i].nodeValue;
alert(productSerial);
}
else {
if (child.nodeType == 1) {
var serial = ("The " + i + ". child is an element node. Contents:\n" + child.innerHTML);
}
}
}
var computer = document.getElementById ("computer");
for (var i = 0; i < computer.childNodes.length; i++) {
var child = computer.childNodes[i];
if (child.nodeType == 3) {
//alert ("The " + i + ". child is a text node. Contents:\n" + child.data);
var computer = computer.childNodes[i].nodeValue;
alert(computer);
}
else {
if (child.nodeType == 1) {
var computer = ("The " + i + ". child is an element node. Contents:\n" + child.innerHTML);
}
}
}
var os = document.getElementById ("os");
for (var i = 0; i < os.childNodes.length; i++) {
var child = os.childNodes[i];
if (child.nodeType == 3) {
//alert ("The " + i + ". child is a text node. Contents:\n" + child.data);
var os = os.childNodes[i].nodeValue;
alert(os);
}
else {
if (child.nodeType == 1) {
var os = ("The " + i + ". child is an element node. Contents:\n" + child.innerHTML);
}
}
}
}
}
理解。 ussteele