0
我有3 TextFields
,稱爲txtUSD
,txtEUR
,txtAUS
。和一個PopupList
具有相同的值,減去txt
部分,但我需要根據用戶所做的選擇形成要使用的名稱TextFields
。所以,我已經做到了這一點:變量和對象的問題
function btConvert_Click(event)
{
var amount = document.getElementById("txtAmount").value;
var rates = document.getElementById("lstConvertTo").value;
var from = "txt" + document.getElementById("lstFrom").options[document.getElementById('lstFrom').selectedIndex].text;
var to = "txt" + document.getElementById("lstConvertTo").options[document.getElementById("lstConvertTo").selectedIndex].text;
var curr_from = document.getElementById(from).value;
var curr_to = document.getElementById(to).value;
if(curr_from > curr_to)
{
amount * rates;
} else {
amount/rates;
}
alert(result);
}
但每次我嘗試它的時候我得到這個錯誤:
mobile/main.js line 215: Result of expression 'document.getElementById(from)' [null] is not an object.
我應該怎麼做呢?
你有ID爲'from'和'to'的元素嗎? – bensiu 2011-04-03 02:16:09
O,男孩純JavaScript非常痛苦:O – arma 2011-04-03 02:17:05
他們都是'value','from'和'to'的值應該是'txt'的組合+所選值 – 2011-04-03 13:02:41