当您单击mBTC,然后尝试单击回到BTC时,它将不起作用。但是,如果您要点一下或坐下再回到BTC,它就可以正常工作。我不明白为什么它没有从mBTC转换为BTC。也许与co​​nvertMBTC函数有关?



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>

最佳答案

bitcoinConversion()开头,您有:

if (currentUnit != MBIT)


因此,如果您最后一次单击mBTC,它不会执行任何操作。该行应为:

if (currentUnit != BTC)

09-13 07:46