制作可运行的 javascript 货币转换器
我在使用以下代码时遇到问题。 这是 html 部分
<form name="convert">
Choose which currency you would like to convert the Euro to:
<select id="conversionType">
<option value="polish">Polish Zloty</option>
<option value="ukraine">Ukraine Hryvnia</option>
</select>
</br>
</br>
<hr>
Amount:<input id="amount" type="text" />
<input id="convertButton" type="button" value="Convert->"/>
To:
<input id="answer" type="text" name="answer" readonly="readonly"/>
</form>
,这是 javascript 代码。 它之前已被更改和帮助过,但我不明白为什么它不起作用,
window.onload = initPage;
var euro;
var convert;
function initPage()
{
document.getElementById("convertButton").onclick = calcAnswer;
document.getElementById("conversionType").onchange = calcAnswer;
}
function calcAnswer()
{
//alert(document.getElementById("conversionType").value);
var value1 = document.getElementById("amount").value1;
var conversionType = document.getElementById("conversionType").value1;
//alert(conversionType);
//if(var value = document.getElementById("conversionType").value=="polish");
// document.getElementById("answer").value=value1 * 4.4976;
//else
// document.getElementById("answer").value=value1* 10.43958;
if(conversionType == "polish") {
document.getElementById("answer").value1=value1 * 4.4976;
} else {
document.getElementById("answer").value1=value1 * 10.43958;
}
}
它根本不起作用。我不知道为什么,因为我认为这个理论是合理的。任何帮助我们将不胜感激
Im having trouble with the following code.
Here is the html part
<form name="convert">
Choose which currency you would like to convert the Euro to:
<select id="conversionType">
<option value="polish">Polish Zloty</option>
<option value="ukraine">Ukraine Hryvnia</option>
</select>
</br>
</br>
<hr>
Amount:<input id="amount" type="text" />
<input id="convertButton" type="button" value="Convert->"/>
To:
<input id="answer" type="text" name="answer" readonly="readonly"/>
</form>
and here is the javascript code.
it has been changed and helped before but i cannot see why it is not working
window.onload = initPage;
var euro;
var convert;
function initPage()
{
document.getElementById("convertButton").onclick = calcAnswer;
document.getElementById("conversionType").onchange = calcAnswer;
}
function calcAnswer()
{
//alert(document.getElementById("conversionType").value);
var value1 = document.getElementById("amount").value1;
var conversionType = document.getElementById("conversionType").value1;
//alert(conversionType);
//if(var value = document.getElementById("conversionType").value=="polish");
// document.getElementById("answer").value=value1 * 4.4976;
//else
// document.getElementById("answer").value=value1* 10.43958;
if(conversionType == "polish") {
document.getElementById("answer").value1=value1 * 4.4976;
} else {
document.getElementById("answer").value1=value1 * 10.43958;
}
}
it will not work at all. i dont know why because i think that the theory is sound. any help wpuld be much appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
任何时候你这样做:
应该是这样:
没有 value1 这样的东西。
Any time you do this:
should be this:
no such thing as value1.
这不应该
是
Shouldn't this
be