0

所以,作为我的第一个项目之一,我尝试做一个小抽奖网站,但我无法在网站上显示winPercentage变量script.js。它只是空着。为什么?

script.js部分:

    var winPercentage = winCount / gameCount * 100;
    document.getElementById("winPercentageID").innerHTML = winPercentage;

HTML部分:

    Your Win Percentage is : <br>
    <span id = "winPercentageId"></span>
4

3 回答 3

1

您的 idwinPercentageID不匹配winPercentageId(大写“ID”与“Id”)

于 2018-04-29T11:50:35.327 回答
0

如果你想用 jQuery 来做。

var winPercentage = winCount / gameCount * 100;
$("#winPercentageID").html(winPercentage)
于 2018-04-29T12:36:31.757 回答
0
Your Win Percentage is : <br>
    <span id = "winPercentageId"></span>

我认为有一个错字问题:

winPercentageIdspan一样document.getElementById("winPercentageID")

改一下就行了...

于 2018-04-29T11:51:14.200 回答