Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中添加localstoarge变量?_Javascript_Html_Css - Fatal编程技术网

如何在javascript中添加localstoarge变量?

如何在javascript中添加localstoarge变量?,javascript,html,css,Javascript,Html,Css,所以,我有我的btc和散列,当我点击开始挖掘时,我希望它每1秒将btc添加到我的余额中,等于我拥有的散列数,所以如果我有1个satoshi和1个散列,我花1秒挖掘,我得到2个btc,然后是4个 你们能检查一下,确保我把计时器放对了吗 我的代码是: <html> <head> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrit

所以,我有我的btc和散列,当我点击开始挖掘时,我希望它每1秒将btc添加到我的余额中,等于我拥有的散列数,所以如果我有1个satoshi和1个散列,我花1秒挖掘,我得到2个btc,然后是4个

你们能检查一下,确保我把计时器放对了吗

我的代码是:

<html>
<head>
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>


<style>
</style>

</head>


<body>
<pre> </pre>
<div class="container">

  <div class="card-deck">
    <div class="card bg-primary">
      <div class="card-body text-center">
    <i class="fab fa-btc" height="32" width ="32"></i>
    <p class="card-text">Satoshis: <span id="btc"></span></p>

      </div>
    </div>
    <div class="card bg-warning">
      <div class="card-body text-center">
        <p class="card-text">Hashs: <span id="hashs"></span></p>
      </div>
    </div>
    <div class="card bg-success">
      <div class="card-body text-center">
        <p class="card-text">upgrades button here with popup tab</p>
      </div>
    </div>
    <div class="card bg-danger">
      <div class="card-body text-center">
        <p class="card-text"><p id="btcmina"><button type="button" onclick="btcmining()" class="btn btn-light">Begin Mining</button></p></p>
      </div>
    </div>  
  </div>
</div>
<pre> </pre>
<div class="container">

  <div class="card-deck">
    <div class="card bg-primary">
      <div class="card-body text-center">
    <i class="fab fa-monero" height="32" width ="32"></i>
    <p class="card-text">monotoshis here</p>

      </div>
    </div>
    <div class="card bg-warning">
      <div class="card-body text-center">
        <p class="card-text">mono hashs here</p>
      </div>
    </div>
    <div class="card bg-success">
      <div class="card-body text-center">
        <p class="card-text">upgrades button here with popup tab</p>
      </div>
    </div>
    <div class="card bg-danger">
      <div class="card-body text-center">
        <p class="card-text">Start mining button here with css button</p>
      </div>
    </div>  
  </div>
</div>

</body>




<script>
var btc = Number(localStorage.getItem("btc") || "1");
var hashs = Number(localStorage.getItem("hashs") || "1");

function btcmining() {
    document.getElementById('btcmina').innerHTML = "<p id=mini><button type=button class=btn btn-primary onclick=stopbtc()>Stop Mining</button></p>";

    updateTimer = setTimeout(updatey, 1000000)
        minebtcTimer = setTimeout(btcmining, 1000);
}

function update() {
  document.getElementById('btc').innerHTML = btc;
  document.getElementById('hashs').innerHTML = hashs;
  localStorage.setItem("btc", btc);
  localStorage.setItem("hashs", hashs);
}
function updatey() {
  document.getElementById('btc').innerHTML = btc;
  document.getElementById('hashs').innerHTML = hashs;
  localStorage.setItem("btc", btc);
  localStorage.setItem("hashs", hashs);
  btcmining()
}
function stopbtc() {
    document.getElementById('mini').innerHTML = "<p id=btcmina><button  type=button onclick=btcmining() class=btn btn-primary>Begin Mining</button></p>"
    clearTimeout(updateTimer);
    clearTimeout(minebtcTimer);
}
update();

/*document.getElementById('ao').onclick = function () {
    btc++;
  update();
}
document.getElementById('hash').onclick = function () {
    hashs++;
  update();
}*/
// <button id="ao">Add One</button>
</script>



</html>

Satoshis:

散列:

使用弹出选项卡升级此处的按钮

开始挖掘

在这里

这里是单哈希

使用弹出选项卡升级此处的按钮

使用css按钮在此处开始挖掘按钮

var btc=Number(localStorage.getItem(“btc”)||“1”); var hashs=Number(localStorage.getItem(“hashs”)||“1”); 函数btcmining(){ document.getElementById('btcmina').innerHTML=“

停止挖掘”

”; updateTimer=setTimeout(updatey,1000000) minebtcTimer=setTimeout(btcmining,1000); } 函数更新(){ document.getElementById('btc')。innerHTML=btc; document.getElementById('hashs')。innerHTML=hashs; setItem(“btc”,btc); setItem(“hash”,hash); } 函数updatey(){ document.getElementById('btc')。innerHTML=btc; document.getElementById('hashs')。innerHTML=hashs; setItem(“btc”,btc); setItem(“hash”,hash); btcmining() } 函数stopbtc(){ document.getElementById('mini').innerHTML=“

开始挖掘” clearTimeout(updateTimer); clearTimeout(minebtcimer); } 更新(); /*document.getElementById('ao').onclick=function(){ btc++; 更新(); } document.getElementById('hash')。onclick=function(){ hash++; 更新(); }*/ //加一


从本地存储器读取号码,添加到其中,然后将新号码存储回本地存储器


这只是添加了
1
,如果你想添加其他内容,你可以用你真正想做的任何计算来替换这一行,比如计算散列数并添加它。

你仍然没有修复变量名与ID之间的冲突,但这不是我现在面临的问题,@Barmar如何将变量添加到localstorage?将localstorage中的变量读入变量。添加到该变量。将变量写入localstorage。@Barmar idk如何做。我不知道更多。但我的东西现在添加了太多的数字,它会添加数万个,并降低页面速度
setInterval(add_to_localstorage, 1000);

function add_to_localstorage() {
    var btc = Number(localStorage.getItem("btc") || "1");
    btc = btc + 1;
    localStorage.setItem("btc", btc);
}