2016-11-29 7 views
0

私のコードでは問題があります。すべてがvar counterを除いてうまく動いていて、divが常に値が26になっているので、divが値を変更していません。私が必要とするものは、更新するたびにWebページにあります。更新された値を参照する必要があります。サイトなどがありますが運はありません。JS counterUPをvarとdivに保存する方法

<head>  
    <script type="text/javascript"> 
    var counter = 26.00 
    var timer; 

    function countUP() { 
     counter = counter + Math.random(); 
     document.getElementById("hugee").innerHTML =(counter).toFixed(5); 
    } 

    </script> 
</head> 

<body onLoad='timer = setInterval("countUP()", 5000);'> 
    <div class="col-xs-9 text-right"> 
    <div class="huge" id="hugee">26.00</div> 
    </div> 
</body> 
+0

あなたのコードは、現在、5秒後にhugee要素内の値を更新します。

ここでは、コードを見ることができます。ページの更新中に値を保持する必要がある場合は、window.localStorageオブジェクトを使用できます。これはこの記事で説明されています:http://stackoverflow.com/questions/16206322/how-to-get-js-variable-to-retain-value-after-page-refresh – Mino

答えて

0
only wait 5 second 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>  
    <script type="text/javascript"> 
    var counter = 0; 
    var timer; 

    function countUP() { 
     counter = counter + Math.random(); 
     document.getElementById("hugee").innerHTML =(counter).toFixed(5); 
    } 

    </script> 
</head> 

<body onLoad='timer = setInterval("countUP()", 5000);'> 
    <div class="col-xs-9 text-right"> 
    <div class="huge" id="hugee"></div> 
    </div> 
</body> 
    </html> 
+0

次回更新時のページは更新された値になります –

関連する問題