我的javascript函數有問題返回正確的值。所以基本上,我預計會出現的是tour_prices-arraylist的價格之一。但實際上什麼都沒有出現。任何幫助表示讚賞。使用javascript函數返回值時出現問題
var tour_prices = new Array();
tour_prices["0"]=3000;
tour_prices["1"]=4400;
tour_prices["2"]=5500;
tour_prices["3"]=6600;
tour_prices["4"]=7700;
function tourPrice() {
var thePrice = 0;
var scheme = document.forms["orderScheme"];
var pickDestination = scheme.elements["destination"];
thePrice = tour_prices[pickDestination.value];
return thePrice;
}
function calculateTotal() {
var totalTourPrice = tourPrice();
var totalPrice = document.getElementById('totalPrice');
totalPrice.innerHTML = "the total tour price is " + totalTourPrice + " usd.";
}
<form action="" id="orderScheme" onsubmit="return false">
<div>
<fieldset>
<legend>Order cruise!</legend>
<b><label>Pick Destination: </label></b>
<select id="destination" name='destination' onchange="calculateTotal()">
<option value="0">destination 1</option>
<option value="1">destination 2</option>
<option value="2">destination 3</option>
<option value="3">destination 4</option>
<option value="4">destination 5</option>
</select>
</fieldset>
<div id="totalPrice" name="totalPrice"></div><br>
\t \t \t \t \t \t \t
<input type='submit' id='submit' value='calculate' onclick="calculateTotal()"></input>
</form>
'tourPrice()();'< - 錯誤 – epascarello
是啊,是我不好。這不是在實際的代碼tho :) – nilsenfacE
該代碼的工作原理如下,問題在哪裏? – RobG