</head>
<style>
.three{
margin: 0px auto;
width:600px;
height:260px;
padding-left: 30px;
margin-top:150px;
border: 1px solid grey;
}
.red{
margin-top: -15px;
width: 460px;
height: 75px;
border: 8px solid red;
}
.blue{
margin-top: -91px;
margin-right: 32px;
float:right;
border:8px solid blue;
}
.box{
width: 52px;
height: 52px;
margin: 10px;
float: left;
border: 2px solid slateblue;
}
.red input{
width:45px;
height: 45px;
background-color: red;
font-size: 30px;
text-align: center;
border-radius: 100%;
color: white;
}
.blue input{
width:45px;
height: 45px;
background-color: blue;
font-size: 30px;
text-align: center;
border-radius: 100%;
color: white;
}
.anniu{
float: left;
padding-left:20px;
margin-top: 30px;
}
button{
margin-left: 10px;
margin-right: 15px;
width:110px;
height: 40px;
font-size: 20px;
}
</style>
<body>
<div class="three">
<h1>双色球开奖(6+1)</h1>
<div class="red">
<div class="box"><input class="redBall" type="text"></div>
<div class="box"><input class="redBall" type="text"></div>
<div class="box"><input class="redBall" type="text"></div>
<div class="box"><input class="redBall" type="text"></div>
<div class="box"><input class="redBall" type="text"></div>
<div class="box"><input class="redBall" type="text"></div>
</div>
<div class="blue">
<div class="box"><input class="blueBall" type="text"></div>
</div>
<div class="anniu">
<button id="startRedBall">红球开始</button>
<button id="stopRedBall">红球停止</button>
<button id="startBlueBall">蓝球开始</button>
<button id="stopBlueBall">蓝球停止</button>
</div>
</div>
<script>
const redBallsInputs = document.querySelectorAll('.redBall');
const blueBallInput = document.querySelector('.blueBall input');
const startRedBalls = document.getElementById('startRedBall');
const stopRedBalls = document.getElementById('stopRedBall');
const startBlueBall = document.getElementById('startBlueBall');
const stopBlueBall = document.getElementById('stopBlueBall');
let isGenerating = false;
function generateRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRedBalls() {
if (!isGenerating) return;
for (const input of redBallsInputs) {
input.value = generateRandomNumber(1, 40);
}
}
function getBlueBall() {
if (!isGenerating) return;
blueBallInput.value = generateRandomNumber(1, 15);
}
startRedBalls.addEventListener('click', () => {
isGenerating = true;
setInterval(getRedBalls, 100);
});
stopRedBalls.addEventListener('click', () => {
isGenerating = false;
});
startBlueBall.addEventListener('click', () => {
isGenerating = true;
setInterval(getBlueBall, 100);
});
stopBlueBall.addEventListener('click', () => {
isGenerating = false;
});
</script>
</body>
谁能帮我改改到底为什么篮球没有效果啊
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
关注修改后的代码
<!DOCTYPE html> <html> <head> <title>双色球开奖(6+1)</title> <style> main { margin: 0 auto; max-width: 800px; text-align: center; padding-top: 50px; } h1 { font-size: 36px; font-weight: bold; } .balls { display: flex; justify-content: center; align-items: center; margin-top: 20px; } .red-balls { display: flex; margin-right: 10px; } .ball { width: 50px; height: 50px; border-radius: 50%; font-size: 24px; font-weight: bold; color: #fff; display: flex; justify-content: center; align-items: center; } .red { background-color: #f44336; border: 2px solid #f44336; } .blue { background-color: #2196f3; border: 2px solid #2196f3; } button { margin-top: 20px; padding: 10px 20px; font-size: 18px; border: none; border-radius: 5px; background-color: #4caf50; color: #fff; cursor: pointer; } </style> </head> <body> <main> <h1>双色球开奖(6+1)</h1> <div class="balls"> <div class="red-balls"> <div class="ball red"></div> <div class="ball red"></div> <div class="ball red"></div> <div class="ball red"></div> <div class="ball red"></div> <div class="ball red"></div> </div> <div class="ball blue"></div> </div> <div class="buttons"> <button id="start-red">开始生成红球</button> <button id="stop-red">停止生成红球</button> <button id="start-blue">开始生成蓝球</button> <button id="stop-blue">停止生成蓝球</button> </div> </main> <script> const redBalls = document.querySelectorAll('.red'); const blueBall = document.querySelector('.blue'); const startRedButton = document.getElementById('start-red'); const stopRedButton = document.getElementById('stop-red'); const startBlueButton = document.getElementById('start-blue'); const stopBlueButton = document.getElementById('stop-blue'); let isGeneratingRed = false; let isGeneratingBlue = false; function generateRandomNumber(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function getRedBalls() { if (!isGeneratingRed) return; for (const ball of redBalls) { ball.textContent = generateRandomNumber(1, 40); } } function getBlueBall() { if (!isGeneratingBlue) return; blueBall.textContent = generateRandomNumber(1, 15); } startRedButton.addEventListener('click', () => { isGeneratingRed = true; setInterval(getRedBalls, 100); }); stopRedButton.addEventListener('click', () => { isGeneratingRed = false; }); startBlueButton.addEventListener('click', () => { isGeneratingBlue = true; setInterval(getBlueBall, 100); }); stopBlueButton.addEventListener('click', () => { isGeneratingBlue = false; }); </script> </body> </html>解决 无用评论 打赏 举报