1
試圖從ID標記中獲取值totalDiv-totalDiv1每個都顯示選定值的結果,然後將它們相加以顯示實時組合的值ID tag totalall但我總是收到NaN。將兩個選定的值一起添加,然後顯示結果JavaScript
<h2>£10 Each</h2>
<select name="iteam1" onChange="calc1()">
<option value="10">1</option>
<option value="20">2</option>
<option value="30">3</option>
<option value="40">4</option>
<option value="50">5</option>
</select>
<div id="totalDiv1">£10</div>
<h2>£10 Each</h2>
<select name="iteam" onChange="calc()">
<option value="10">1</option>
<option value="20">2</option>
<option value="30">3</option>
<option value="40">4</option>
<option value="50">5</option>
</select>
<div id="totalDiv">£10</div>
<br>
<h2>Total</h2>
<div id="totalall">£0</div>
<script>
function calc() {
var fruitOrVeg = document.getElementsByName("iteam")[0].value;
var total = fruitOrVeg;
document.getElementById("totalDiv").innerHTML= "£" +(total);
}
</script>
<script>
function calc1() {
var fruitOrVeg = document.getElementsByName("iteam1")[0].value;
var total = fruitOrVeg;
document.getElementById("totalDiv1").innerHTML= "£" +(total);
}
</script>
<script>
window.onload = function total() {
var y = document.getElementById("totalDiv").value;
var z = document.getElementById("totalDiv1").value;
var x = +y + +z;
document.getElementById("totalall").innerHTML = "£" + x;
}
</script>
謝謝,這對我有效 – magi4000 2014-12-06 11:02:27