2017-01-17 6 views
0

私はクイズを持っています。最後のページを読み込むと100%が得られたら、「あなたは100%得ました!」と警告します。 すべての要素が読み込まれた後の警告

var chanceoflive1 = parseInt(localStorage.getItem("chanceoflive1")); 
 
    var chanceoflive2 = parseInt(localStorage.getItem("chanceoflive2")); 
 
    var chanceoflive3 = parseInt(localStorage.getItem("chanceoflive3")); 
 
    var chanceoflive4 = parseInt(localStorage.getItem("chanceoflive4")); 
 
    var chanceoflive7 = parseInt(localStorage.getItem("chanceoflive7")); 
 

 
    var chanceoflivefinal = (chanceoflive1||0) + (chanceoflive2||0) + (chanceoflive3||0) + (chanceoflive4||0) + (chanceoflive7||0); 
 
    var chanceoflivepercent = chanceoflivefinal * 4; 
 
    
 

 
function startup(){ 
 
     if (chanceoflivefinal == 25) { 
 
      alert("You Got 100%!"); 
 
     } 
 
    }
<body onload="startup"> 
 
<center> 
 
    <h2 class="text">Final Results</h2> 
 

 
    <p id="print" class="text"></p> 
 
    <p id="print2" class="text"></p> 
 

 
    <img src="qrcode.jpg" height="300" length="300"> 
 

 
    <br> 
 

 
    <div class="wrapper"> 
 
     <a href="index.html"> 
 
    <button align=center onclick="handleClick()" id="button"> 
 
     <canvas width="200" height="50" id="canvas" align=center></canvas> 
 
     <span class="text" id="submit">Retry</span> 
 
    </button> 
 
     </a> 
 
    </div> 
 
    </center> 
 
    </body>

がどのように私はこの問題を解決することができます。が、これは私のコードでのバックグラウンドロードの前でロードしますか?

+2

'onload =" startup() "'を呼び出す関数の後に '()'を入れる必要があります。 – Barmar

答えて

1

使用することができます。として

(function(){ // on document load 
    alert("Ready!"); // alert "ready" 
})(); 

ああ、と@バーマーが言った、それはと呼ぶ、あなたは変更する必要がありますstartupstartup()

+0

ありがとう!私は関数の後に '()'を置くのを忘れていたとは思えません。私はノブのように感じる。 –

0

();のようなものはありません。onload="startup();"です。

おそらく、あなたもあなたはいつもscriptタグ内でこのような何かを行うことができ

document.onload = startup(); 

あるいは

window.onload = startup(); 
関連する問題