function generate() { var redBalls = []; while (redBalls.length < 6){ var num = Math.floor(Math.random() * 33) + 1; if (redBalls.indexOf(num) === -1) { redBalls.push(num); } } redBalls.sort(function(a,b){ return a - b; }); var blueBall = Math.floor(Math.random() * 16) + 1; var result = redBalls.map(num => (num < 10 ? '0' + num : num.toString())).join(" ") + " " + (blueBall < 10 ? '0' + blueBall : blueBall.toString()); displayResult(result); } function displayResult(result){ var container = document.getElementById("ball-container"); container.innerHTML = ""; for (var i = 0; i <6; i++) { var ball = document.createElement("div"); ball.classList.add("red-ball"); ball.innerHTML = result.split(" ")[i]; container.appendChild(ball); } var ball = document.createElement("div"); ball.classList.add("blue-ball"); }代码有没有问题
时间: 2024-01-26 13:04:33 浏览: 20
这段代码似乎存在一个问题,`displayResult`函数中创建了一个蓝球的`div`元素,但没有将其添加到`container`中。可能需要在函数中添加以下代码:
```
ball.innerHTML = result.split(" ")[6];
container.appendChild(ball);
```
阅读全文