0
값이 "0"일 때 내 코드가 정보를 표시하지 않게하려면 이벤트 또는 조치가 필요합니다. 일반적으로 값이 1보다 크면 XML 정보가 표시되며 X가 선택 되어도 이전 XML 데이터가 표시되지만 비어 있어야합니다.0 값으로 정보를 숨기는 방법을 모르십니까?
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet" /></head>
<body>
<form>
<select id="pullDownList" onchange="myFunction();">
<option value="0">Please Choose a Country</option>
<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","./cords_data.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var xmlDocument=xmlDoc.getElementsByTagName("Row");
for (i=0;i<xmlDocument.length;i++)
{
document.write("<option value='");
document.write(i+1);
document.write("'>");
document.write(xmlDocument[i].getElementsByTagName("Country")[0].childNodes[0].nodeValue);
}
</script></select>
<p />
<div id=fieldInfo1></div>
<div id=fieldInfo2></div>
<div id=fieldInfo3></div>
<div id=fieldInfo4></div>
</p>
<script>
function myFunction()
var z = document.getElementById("pullDownList").selectedIndex-1;
if (pullDownList.value == "0"){
}else {
document.getElementById("fieldInfo1").innerHTML = xmlDocument[z].getElementsByTagName("Country")[0].childNodes[0].nodeValue;
document.getElementById("fieldInfo2").innerHTML = xmlDocument[z].getElementsByTagName("Voltage")[0].childNodes[0].nodeValue;
document.getElementById("fieldInfo3").innerHTML = xmlDocument[z].getElementsByTagName("Freq__Hz")[0].childNodes[0].nodeValue;
document.getElementById("fieldInfo4").innerHTML = xmlDocument[z].getElementsByTagName("Cord_Designator")[0].childNodes[0].nodeValue;
}
</script>
그런 다음 XML 항목은 그 아래에있는 다른 항목으로 이동해야합니까? – shaysilv
수정하십시오. 이 이벤트가 언제 발생하는지 (예 : 페이지로드, 버튼 클릭, 필드 변경 등) 원하는지 확신 할 수 없지만 페이지로드시 눈이 내리므로 0 값을 확인한 다음 실행하십시오 그 분야에서 당신이 원하는 일. 그러므로 else 문은 그것을 덮어야합니다. – mwilson
대단히 감사합니다! 그것은 작동합니다. – shaysilv