制作可运行的 javascript 货币转换器

发布于 2024-12-21 10:22:53 字数 1604 浏览 1 评论 0原文

我在使用以下代码时遇到问题。 这是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自演自醉 2024-12-28 10:22:53

任何时候你这样做:

document.getElementById("amount").value1

应该是这样:

document.getElementById("amount").value

没有 value1 这样的东西。

Any time you do this:

document.getElementById("amount").value1

should be this:

document.getElementById("amount").value

no such thing as value1.

丘比特射中我 2024-12-28 10:22:53

这不应该

<pre> document.getElementById("answer").value1 </pre>

 document.getElementById("answer").value = value1 * 4.4976 

Shouldn't this

<pre> document.getElementById("answer").value1 </pre>

be

 document.getElementById("answer").value = value1 * 4.4976 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文