gpt4 book ai didi

javascript - document.getElementById().style.display = 'block' ;不工作

转载 作者:太空宇宙 更新时间:2023-11-04 06:22:45 29 4
gpt4 key购买 nike

我正在编写我的第一个 JavaScript 程序……我的第一个程序。这是一个掷骰子的小游戏。我需要做的部分事情是在隐藏的表格中显示一些游戏结果。目前,当执行该功能时,表格会闪烁一秒钟,然后再次隐藏。我正在使用 style="display:none"style.display = "block" 有谁知道是什么导致了这个问题?谢谢!

function rollDice() {
let bet = document.getElementById("startingBet").value;
let rollCount = 0;
if (bet <= 0) {
alert("You must place a bet");
}
else {
let gameMoney = bet;
while (gameMoney > 0) {
let snake = Math.floor(Math.random() * 6) +1;
let eyes = Math.floor(Math.random() * 6) +1;
let total = snake + eyes;
rollCount++;
console.log(gameMoney);
console.log(rollCount);
if (total == 7) {
gameMoney = gameMoney + 4;
}
else {
gameMoney--;
}
}
if (gameMoney <= 0) {
alert("Game Over")
}

}
document.getElementById("hide").style.display = 'block';
document.getElementById("startBet").innerText = "$" + bet;
}
<!DOCTYPE html>
<html>
<head>
<title>Lucky Sevens</title>

<style type="text/css">

#startingBet {
width: 50px;
}

</style>

</head>


<body>
<main>
<header>
<center><h1>Lucky Sevens</h1></center>
</header>

<form action="luckysevens.html" onsubmit="rollDice()">
<center><p>Starting Bet: <input type="number" placeholder="$0.00" id="startingBet" step="0.01"/></p>
<input type="submit" id="play" value="Play" /></center>
</form>




<div id="hide" style="display:none;">
<hr width="25%">
<table id="results" align="center" >
<thread>
<caption><h2>Results</h2></caption>
<tr>
<th>Starting Bet</th>
<th><span id="startBet"></span></th>
</tr>
</thread>
<tbody>
<tr>
<td>Total Rolls Before Going Broke</td>
<td><span id="totalRolls"></span></td>
</tr>
<tr>
<td>Highest Amount Won</td>
<td><span id="pinacle"></span></td>
</tr>
<tr>
<td>Roll Count at Highest Amount Won</td>
<td><span id="highRollCount"></span></td>
</tr>
</tbody>
</table>
</div>


<script src="luckysevens.js"></script>

</main>
</body>
</html>

最佳答案

尝试:

document.getElementById('hide').style.cssText = "display: block;"; 

document.getElementById('hide').setAttribute("style", "display: block;");

关于javascript - document.getElementById().style.display = 'block' ;不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55331920/

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