2014-02-24 42 views
0

我有一些麻煩讓我的代碼正常工作,一旦它被加載到我的網站上。雖然它在我的.html編輯器中,但它工作正常,但是一旦我將它放在服務器上,它就不會(您可以在@http://www.jump2it.net/delivery.html上看到它)。html下拉框在編輯器中工作,但不在瀏覽器中

該代碼應該允許您從下拉框中選擇一個城市名稱,然後在一個文本框中顯示該城市的最低租賃金額以及第二個文本框中該城市的交付金額。當我在編輯器中運行代碼時,它運行良好,但是一旦我將其上傳或在我的計算機上本地運行它,它就會在兩個文本框中給出「未定義」的答案。

任何幫助,你可以扔我的方式將不勝感激。謝謝!

這裏是我的腳本:

<script type="text/javascript"> 
    function AnEventHasOccurred() 
     { 
      var sel = document.getElementById("selectone"); 
      document.getElementById("eventlog1").value = "" + "" + sel.options[sel.selectedIndex].value1 + "\n"; 
      document.getElementById("eventlog2").value = "" + "" + sel.options[sel.selectedIndex].value2 + "\n"; 
     } 
</script></p> 

這裏是我的.html代碼:

<table border="1" width="60%" height="17"> 
    <tr> 
    <td width="40%" height="11" align="left" valign="top"> 
    <p style="margin:0;"><b>Please Choose Your City and Zipcode Below</b></p> 
    <p style="margin:0;">&nbsp;</p> 
    <p style="margin:0;"><b>&nbsp;</b><select id="selectone" onchange="AnEventHasOccurred()"> 
     <option value=""></option> 
     <option value1="$100" option value2="FREE">Peachtree City - 30269</option> 
     <option value="Newnan - Min. Rental=$100, Delivery=Free">Newnan - 30265</option> 
     <option value="Newnan - Min. Rental=$100, Delivery=Free">Newnan - 30263</option> 
    </select></p> 
</td> 
<td width="43%" height="11"> 
<p style="margin:0;"><b>Min. Rental Amount</b></p> 
<p style="margin:0;">&nbsp;</p> 
    <INPUT TYPE="text" ID="eventlog1" NAME="result" VALUE="" size="20"/> 
</td> 
<td width="34%" height="11"> 
<p style="margin: 0"><b>Delivery Fee</b></p> 
<p style="margin: 0">&nbsp;</p> 
    <INPUT TYPE="text" ID="eventlog2" NAME="result" VALUE="" size="20"/> 
</td> 
</tr> 
</table> 

回答

0

改變你的JavaScript代碼:

document.getElementById("eventlog1").value = "" + "" + 
       sel.options[sel.selectedIndex].getAttribute('value1') + "\n"; 
    document.getElementById("eventlog2").value = "" + "" + 
       sel.options[sel.selectedIndex].getAttribute('value2') + "\n"; 

DEMO

+0

謝謝梅達。這固定在第一次嘗試! – user3344773

0

嘗試通過屬性訪問。

sel.options[sel.selectedIndex].attributes["value1"] 
相關問題