var select;
window.onload = function() {
var select = document.getElementById("money");
console.log(select);
}
function changedepositedInput(objDropDown) {
console.log(parseInt(objDropDown));
var objdeposited = document.getElementById("deposited");
objdeposited.value=parseInt(objdeposited.value);
var total=parseInt(objdeposited.value);
objdeposited.value = parseInt(objDropDown.value+total);
objdeposited.value = parseInt(objdeposited.value);
}
</script>
<h1>Vending Machine Project</h1>
<form name="vendingmachine" action=" ">
Choose Bevrage<br>
<input name="item" type="radio" value="water" checked="checked">Water 75 cents<br>
<input name="item" type="radio" value="soda">Soda $1.50<br>
<input name="item" type="radio" value="coffee">Coffee $1.00<br>
<input name="item" type="radio" value="beer">Beer $2.00<br>
<p>
<label>Deposit Money:
<select name="money" id="money" onchange="changedepositedInput(this)">
<option>Choose Amount</option>
<option value="10">10 cents</option>
<option value="25">25 cents</option>
<option value="50">50 cents</option>
<option value="75">75 cents</option>
<option value="100">$1.00</option>
</select>
</label>
</p>
<p>Total Deposited:<input name="deposited" id="deposited" type="text" readonly="TRUE" value=" "></p>
使用此代碼我沒有得到一個固體數字的回報,例如在下拉菜單中我會選擇兩個值,即50和75,他們將結合爲5075,是這是否意味着它仍然在字符串的某個地方運行,如果是的話呢?parseInt沒有得到額外的回報
您正在重新聲明'select'。 'var'在範圍內聲明一個_local_變量。 – elclanrs
我需要做些什麼來改變這一點,對不起,我對此感到新奇,謝謝! – joro4651