我正在为密码制作货币转换器,但我遇到了问题。这是源代码。现在我尝试了几种方法使其工作,但我要么没有成功,要么只是部分成功。
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>
任何帮助都表示赞赏,希望这会很好。
答案 0 :(得分:0)
在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 ...
}
同样在条件语句中,您使用了赋值运算符=
而不是逻辑运算符来比较这两个值。我假设您要使用===
或==
。