货币转换器从美元到欧元或任何其他货币的HTML和JavaScript

时间:2014-05-17 21:39:37

标签: javascript html concurrency converter

我想转换货币,但这个货币对我不起作用                    将美元兑换成欧元2                                    

                量:                              

            

              从                                美元                 欧元                              至                            美元               欧元                          

            

                           

            

                                              

        

<script type="text/javascript">
    function calculate() {
        var amount = parseFloat(document.getElementById("amount").value);
        var select = document.getElementById("select");
        var select = document.getElementById("select2");

        var result = document.getElementById("result");

        if ((select.value == "USD" ) && (select.value == "EUR")){

            result.value = (amount * 0.7003).toFixed(2);
        }


        else if ((select.value === "EUR") && (select.value == "USD")) {
            result.value = (amount * 1.4283).toFixed(2);
        }
        else  {
             result.value = (amount);
        }

    }
</script>
</body>
   </html>

2 个答案:

答案 0 :(得分:2)

您无法为指向两个不同DOM元素的变量指定一个名称,并期望它们按您希望的方式运行。您应该使用不同的名称(例如, select1 select2 ),如下例所示:

   function calculate() {
    var amount = parseFloat(document.getElementById("amount").value)
    var select1 = document.getElementById("select")
    var select2 = document.getElementById("select2")
    var result = document.getElementById("result")

    if ((select1.value == "USD" ) && (select2.value == "EUR")){
        result.value = (amount * 0.7003).toFixed(2)
    } else if ((select1.value == "EUR") && (select2.value == "USD")) {
        result.value = (amount * 1.4283).toFixed(2)
    } else {
        result.value = (amount)
    }

}

答案 1 :(得分:-1)

扩展 Notulysses &#39;回答, selectFromselectTo会更健谈。