货币转换器不适用于 Javascript 和 HTML

Currency Converter Not Working with Javascript & HTML

我正在制作一个用于加密货币的货币转换器,但我在使用它时遇到了问题。这是源代码。现在我尝试了几种方法使它起作用,但我要么没有成功,要么只是部分成功。

HTML:

         <html>
           <head>
           </head>
           <body>

            <input oninput="convert()" onchange="convert()"  type="value" name="input" id="currencycoininsert" placeholder="0.00"/>
        <!--    <button type="button" id="btncur-insert"> -->
                <select name="dropdowncurrency" id="selectcurinsert">
                    <option value="BTC" id="selectcurinsert1" >BITCOIN (BTC)</option>
                    <option value="ETH" id="selectcurinsert2"  selected>ETHERIUM (ETH)</option>
                    <option value="LTC" id="selectcurinsert3" >LITECOIN (LTC)</option>
                    <option value="ZEC" id="selectcurinsert4" >ZCASH (ZEC)</option>
                    <option value="XMR" id="selectcurinsert5" >MONERO (XMR)</option>
                </select>
        <!--    </button> -->
            <button type="submit" name="smbtcur" id="sbmtcurinsert" onclick="convert()">
            Convert
            </button>
            <input type="value" id="received"/>

         </body>
         </html>

感谢任何帮助。 这是 Javascript 部分: JS:

                var rates = [10500, 920, 220, 310, 460];

                var BTCUSD = rates[0];
                var ETHUSD = rates[1];
                var LTCUSD = rates[2];
                var XMRUSD = rates[3];
                var ZECUSD = rates[4];

            function convert(){


                var x1 = document.getElementById("selectcurinsert1").value;
                var x2 = document.getElementById("selectcurinsert2").value;
                var x3 = document.getElementById("selectcurinsert3").value;
                var x4 = document.getElementById("selectcurinsert4").value;
                var x5 = document.getElementById("selectcurinsert5").value;
                if (document.getElementById("selectcurinsert").value = x1)
                {
                  function convertbtc()
                {   
                        z = BTCUSD;
                        x = document.getElementById("currencycoininsert").value;
                        document.getElementById("receivedmufg").value = x * z;   
                }
                }
                else if (document.getElementById("selectcurinsert").value = x2)
                {
                function converteth()
                {

                        z = BTCUSD;
                        x = document.getElementById("currencycoininsert").value;
                        document.getElementById("receivedmufg").value = x * z; 

                }
                }
                else if (document.getElementById("selectcurinsert").value = x3)
                {
                function converteth()
                {

                        z = BTCUSD;
                        x = document.getElementById("currencycoininsert").value;
                        document.getElementById("receivedmufg").value = x * z; 

                }
                }
                else if (document.getElementById("selectcurinsert").value = x4)
                {
                function converteth()
                {

                        z = BTCUSD;
                        x = document.getElementById("currencycoininsert").value;
                        document.getElementById("receivedmufg").value = x * z; 

                }
                }
                else if (document.getElementById("selectcurinsert").value = x5)
                {
                function converteth()
                {

                        z = BTCUSD;
                        x = document.getElementById("currencycoininsert").value;
                        document.getElementById("receivedmufg").value = x * z; 

                }
                }
                }


            </script>

感谢任何帮助,希望一切顺利。

在您的 convert 函数定义中,您在条件语句中定义了其他函数,但您从未实际调用这些函数。

您可以在其他地方定义 converteth 等,并在条件语句中像 converteth() 一样调用它。

伪代码:

function converteth () {
    ... converteth code ...
}

function convertbtc () {
    ... convertbtc code ...
}

function convert () {
    ... get element by id statements
    if (document.getElementById("selectcurinsert").value = x1) {
        convertbtc();
    } ... other conditional statements ...
}

此外,在您的条件语句中,您使用了赋值运算符 = 而不是逻辑运算符来比较两个值。我假设您想使用 =====.