gpt4 book ai didi

javascript - 所有元素加载后发出警报

转载 作者:行者123 更新时间:2023-12-03 05:13:54 25 4
gpt4 key购买 nike

我有一个测验,如果你得到了 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>

我该如何解决这个问题?

最佳答案

您始终可以在 script 标记中执行类似的操作:

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

哦,正如@Barmar所说,要调用该函数,您需要将startup更改为startup()

关于javascript - 所有元素加载后发出警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41688130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com