我試圖讓我的標籤顯示一個xml文件的名稱,我目前有鏈接在觸發時改變顏色和文本,但我希望它得到它的原始狀態名稱來自xml文件。Javascript和XML的innerHTML命名
我只對這裏的輸入鏈接感興趣。
這是事物的HTML端:
<div id="status">
<div id="loading" style="display:none">Error:<br />Connection to EMACSYS board was lost.</div>
<div id="display">
<p></span></p>
<p>Inputs:<br /><span style="font-size:20pt"></p>
<a id="btn0">• Input 1</a><br>
<a id="btn1">• Input 2</a><br>
<a id="btn2">• Input 3</a><br>
<a id="btn3">• Input 4</a><br>
<a id="btn4">• Input 5</a><br>
<a id="btn5">• Input 6</a><br>
<a id="btn6">• Input 7</a><br>
<a id="btn7">• Input 8</a><br>
<a id="btn8">• Input 9</a><br>
<a id="btn9">• Input 10</a><br>
<a id="btn10">• Input 11</a><br>
<a id="btn11">• Input 12</a><br>
<a id="btn12">• Input 13</a><br>
<a id="btn13">• Input 14</a><br>
<a id="btn14">• Input 15</a><br>
<a id="btn15">• Input 16</a><br>
</span> </p>
<p>Canopy Temperature: <a id="analogue0">?</a>
<br /><span style="font-size:20pt">
<a id="pot0">›</a>
<a id="pot1">›</a>
<a id="pot2">›</a>
<a id="pot3">›</a>
<a id="pot4">›</a>
<a id="pot5">›</a>
<a id="pot6">›</a>
<a id="pot7">›</a>
<a id="pot8">›</a>
<a id="pot9">›</a>
</span></p>
<p>Engine Heater Temperature: <a id="analogue1">?</a> (30-90 normal)
<br /><span style="font-size:20pt">
<a id="1pot0">›</a>
<a id="1pot1">›</a>
<a id="1pot2">›</a>
<a id="1pot3">›</a>
<a id="1pot4">›</a>
<a id="1pot5">›</a>
<a id="1pot6">›</a>
<a id="1pot7">›</a>
<a id="1pot8">›</a>
<a id="1pot9">›</a>
</span></p>
</div>
所有似乎確定,當輸入觸發工作正常,但它說:輸入1,輸入2,等我想它加載從這個XML文件inputname標籤
<response>
<input0>~Inputs(1)~</input0>
<inputname0>Mains OK</inputname0>
<input1>~Inputs(2)~</input1>
<inputname1>Water Heater</inputname1>
<input2>~Inputs(3)~</input2>
<inputname2>Genset Standby</inputname2>
<input3>~Inputs(4)~</input3>
<inputname3>Genset Running</inputname3>
<input4>~Inputs(5)~</input4>
<inputname4>Common Alarm</inputname4>
<input5>~Inputs(6)~</input5>
<inputname5>Genset Shutdown Alarm</inputname5>
<input6>~Inputs(7)~</input6>
<inputname6>Genset Fuel Tank 1/2</inputname6>
<input7>~Inputs(8)~</input7>
<inputname7>Genset Fuel Tank 1/4</inputname7>
<input8>~Inputs(9)~</input8>
<inputname8>Genset Fuel Tank Low</inputname8>
<input9>~Inputs(10)~</input9>
<inputname9>option</inputname9>
<input10>~Inputs(11)~</input10>
<inputname10>option</inputname10>
<input11>~Inputs(12)~</input11>
<inputname11>Bulk Fuel Full</inputname11>
<input12>~Inputs(13)~</input12>
<inputname12>Bulk Fuel 3/4</inputname12>
<input13>~Inputs(14)~</input13>
<inputname13>Bulk Fuel 1/2</inputname13>
<input14>~Inputs(15)~</input14>
<inputname14>Bulk Fuel 1/4</inputname14>
<input15>~Inputs(16)~</input15>
<inputname15>Bulk Fuel Low</inputname15>
<output0>~Outputs(1)~</output0>
<output1>~Outputs(2)~</output1>
<output2>~Outputs(3)~</output2>
<output3>~Outputs(4)~</output3>
<output4>~Outputs(5)~</output4>
<output5>~Outputs(6)~</output5>
<output6>~Outputs(7)~</output6>
<output7>~Outputs(8)~</output7>
<output8>~Outputs(9)~</output8>
<output9>~Outputs(10)~</output9>
<output10>~Outputs(11)~</output10>
<output11>~Outputs(12)~</output11>
<output12>~Outputs(13)~</output12>
<output13>~Outputs(14)~</output13>
<output14>~Outputs(15)~</output14>
<output15>~Outputs(16)~</output15>
<analogue0>~Analogs(1,T,2,3977)~</analogue0>
<analogue1>~Analogs(2)~</analogue1>
<analogue2>~Analogs(3)~</analogue2>
<analogue3>~Analogs(4)~</analogue3>
<analogue4>~Analogs(5)~</analogue4>
<analogue5>~Analogs(6)~</analogue5>
<analogue6>~Analogs(7)~</analogue6>
<analogue7>~Analogs(8)~</analogue7>
</response>
因此,對於輸入1它會顯示電源OK,那麼當它被觸發時,它會自動顯示警告,然後再返回到主電源OK時,它才恢復正常。
我試過幾件事情在JavaScript:
<script type="text/javascript">
// Parses the xmlResponse from status.xml and updates the status box
function updateStatus(xmlData) {
// Check if a timeout occurred
if(!xmlData)
{
document.getElementById('display').style.display = 'none';
document.getElementById('loading').style.display = 'inline';
return;
}
// Make sure we're displaying the status display
document.getElementById('loading').style.display = 'none';
document.getElementById('display').style.display = 'inline';
// Loop over all the LEDs
for(i = 0; i < 16; i++) {
if(getXMLValue(xmlData, 'input'+i) == '1') {
document.getElementById('btn' + i).style.color = '#d00';
document.getElementById('btn' + i).innerHTML = '• ALERT';
}
else {
document.getElementById('btn' + i).style.color = '#090';
document.getElementById('btn' + i).innerHTML = ('•)getXMLValue(xmlData, 'inputname'+i);
}
}
// Loop over all the buttons
// Update the POT value
document.getElementById('analogue0').innerHTML =getXMLValue(xmlData,'analogue0');
val=0;
for(i = 0; i < 10; i++) {
val=val+10;
if(getXMLValue(xmlData, 'analogue0') >val)
document.getElementById('pot' + i).style.color = '#090';
else
document.getElementById('pot' + i).style.color = '#fff';
}
// Update the POT value 2
document.getElementById('analogue1').innerHTML =getXMLValue(xmlData,'analogue1');
val=0;
for(i = 0; i < 10; i++) {
val=val+10;
if(getXMLValue(xmlData, 'analogue1') >val)
document.getElementById('1pot' + i).style.color = '#090';
else
document.getElementById('1pot' + i).style.color = '#fff';
}
}
setTimeout("newAJAXCommand('status.xml', updateStatus, true)",500);
</script>
,但不是任何運氣。我很確定它的JavaScript部分,因爲這是我最薄弱的部分。
我會進一步建議一個好的網絡調試器,如「FireBug」,會幫助找到這個問題。 – 2012-01-09 15:22:32