gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:42:01 24 4
gpt4 key购买 nike

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

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 ...
}

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

关于javascript - 货币转换器不适用于 Javascript 和 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48851835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com