首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript转换不工作

Javascript转换不工作
EN

Stack Overflow用户
提问于 2015-10-15 04:17:55
回答 1查看 64关注 0票数 0

当您单击mBTC,然后尝试单击BTC时,它不起作用。然而,如果你去咬或坐,然后回到BTC,它工作得很好。我不明白为什么它没有从mBTC转换到BTC。也许与convertMBTC函数有关?

代码语言:javascript
复制
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);
  }
}
代码语言:javascript
复制
<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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-15 04:32:24

bitcoinConversion()的开头,您有:

代码语言:javascript
复制
if (currentUnit != MBIT)

所以,如果你最后一次点击mBTC,它什么也不会做。这一行应是:

代码语言:javascript
复制
if (currentUnit != BTC)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33139811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档