当您单击mBTC然后尝试单击返回BTC时,它不起作用。然而,如果你去咬或坐回BTC它工作正常。我不明白为什么它没有从mBTC转换为BTC。也许与convertMBTC功能有关?
var SAT = 0.00000001;
var BIT = 0.000001;
var MBIT = 0.001;
var BTC = 1;
var currentUnit = BTC;
function changeColor(div) {
document.getElementById('satoshiBox').style.background = '#29b8ff';
document.getElementById('bitBox').style.background = '#29b8ff';
document.getElementById('BTCBox').style.background = '#29b8ff';
document.getElementById('mBTCBox').style.background = '#29b8ff';
document.getElementById(div).style.background = '#ed546a';
}
function satoshiConvert(input) {
if (currentUnit != SAT) {
input.value = (convertBTC(input.value) / SAT).toFixed(0);
currentUnit = SAT;
changeColor('satoshiBox');
btcConvert(input);
}
}
function bitConvert(input) {
if (currentUnit != BIT) {
input.value = (convertBTC(input.value) / BIT).toFixed(2);
currentUnit = BIT;
changeColor('bitBox');
btcConvert(input);
}
}
function mBTCConvert(input) {
if (currentUnit != MBIT) {
input.value = (convertBTC(input.value) / MBIT).toFixed(4);
currentUnit = MBIT;
changeColor('mBTCBox');
btcConvert(input);
}
}
function bitcoinConversion(input) {
if (currentUnit != MBIT) {
input.value = (convertBTC(input.value) / BTC).toFixed(8);
currentUnit = BTC;
changeColor('BTCBox');
btcConvert(input);
}
}
<div class="bitcoin">
<div class="rateboxy">
<input value="1" type="text" name="btc" id="btc" class="rate" onchange="btcConvert(this);" onkeyup="btcConvert(this);" />
</div>
</div>
<div class="unitBox">
<div class="smallUnitBox" onclick="satoshiConvert(btc);" id="satoshiBox">sat</div>
<div class="smallUnitBox" onclick="bitConvert(btc);" id="bitBox">bit</div>
<div class="smallUnitBox" onclick="mBTCConvert(btc);" id="mBTCBox">mBTC</div>
<div class="smallUnitBox2" onclick="bitcoinConversion(btc);" id="BTCBox">BTC</div>
</div>
<p id="equals">=</p>
<div class="rateboxy">
<input value="<?php echo $bitcoinPrice; ?>" type="text" name="cur" id="cur" class="rate" onchange="usdConvert(this);" onkeyup="usdConvert(this);" />
</div>
</div>
</center>
答案 0 :(得分:1)
在bitcoinConversion()
开始时你有:
if (currentUnit != MBIT)
如果您上次点击mBTC
,它就不会做任何事情。该行应该是:
if (currentUnit != BTC)