개인적 미리
가
function dropDownAction(){
var tempDist=document.HDForm.HuntingDistrict.value;
var tempDesc=xmlDoc.getElementsByTagName("DISTRICT")[tempDist].getAttribute("LegalDesc");
document.getElementById("field2").innerHTML=tempDesc;
}
감사, I는 배열로 모든 행을로드하는 것 (키로서 지구를 사용); 다음 단순히 배열에서 설명을 얻으십시오.
var xmlDoc = // load doc
var elementsToLoopThru=xmlDoc.getElementsByTagName("row");
var rowArray = new Array();
// go thru all the rows
for (var i = 0;i<elementsToLoopThru.length;i++){
var district = "";
var description = "No Description";
var currRowChildren = elementsToLoopThru[i].childNodes;
// go thru all the elements of a row and get the district and description
for (var j = 0;j < currRowChildren.length; j++){
if (currRowChildren[j].nodeName == "DISTRICT"){
district = currRowChildren[j].childNodes[0].nodeValue;
}
else if (currRowChildren[j].nodeName == "LegalDesc"){
description = currRowChildren[j].childNodes[0].nodeValue;
}
}
// if district and description found, enter them as key value pair into array
if (district != ""){
rowArray[district] = description;
alert(district + ": " + description); // DELETE ME
}
}
내 코드를 다시 확인하십시오. 내가이 일을해야한다고 생각하지만, 난 당신이 가치를 얻을 필요가있을 때
그런 다음, 단순히이 경우 작업을해야 rowArray[NAME_OF_DISTRICT]
에 액세스 꽤 녹슨 항해의 XML을이다 :
을 ORDERED인지와는 상관없이 것은 jsfiddle입니다 : http://jsfiddle.net/RwE9s/15/
은 지구가 유일합니다 (한 행에 100 개의 지구가 있음)? – Tomas