//array
window.onload = myFunction();
function myFunction(){
var stroreRandom = [];
for (var i = 0; i <= 25; i++){
var random = Math.floor((Math.random() * 78) + 1);
storeRandom.push(random);
x = document.getElementById("demo");
x.innerHTML = storeRandom;
}
}
<!DOCTYPE html>
<html>
<head>
<link rel= "stylesheet" type = "text/css" href ="css/mystyle.css">
</head>
<body>
<Table id = table>
<tr>
<td class = "bingocell">1</td>
<td class = "bingocell">2</td>
<td class = "bingocell">3</td>
<td class = "bingocell" id = 4>4</td>
<td class = "bingocell" id = 5>5</td>
</tr>
<tr>
<td class = "bingocell" id = 6>1</td>
<td class = "bingocell" id = 7>2</td>
<td class = "bingocell" id = 8>3</td>
<td class = "bingocell" id = 9>4</td>
<td class = "bingocell" id = 10>5</td>
</tr>
<tr>
<td class = "bingocell" id = 11>1</td>
<td class = "bingocell" id = 12>2</td>
<td class = "bingocell" id = 13>3</td>
<td class = "bingocell" id = 14>4</td>
<td class = "bingocell" id = 15>5</td>
</tr>
<tr>
<td class = "bingocell" id = 16>1</td>
<td class = "bingocell" id = 17>2</td>
<td class = "bingocell" id = 18>3</td>
<td class = "bingocell" id = 19>4</td>
<td class = "bingocell" id = 20>5</td>
</tr>
<tr>
<td class = "bingocell" id = 21>1</td>
<td class = "bingocell" id = 22>2</td>
<td class = "bingocell" id = 23>3</td>
<td class = "bingocell" id = 24>4</td>
<td class = "bingocell" id = 25>5</td>
</tr>
</Table>
<p>Click the button to display a random number between 1 and 78.</p>
<button id = "button" onclick = "myFunction()">Try it</button>
<p id="demo"></p>
<!--
<script>
function myFunction() {
var x = document.getElementById("demo")
x.innerHTML = Math.floor((Math.random() * 78) + 1);
}</script>
-->
<script src = "js/script.js"></script>
</body>
</html>
目标是制作一个宾果卡,它会自动从1-78生成25个唯一数字,我决定通过将随机数字存储在数组中并通过appendChild将它们分配给表的方式来做到这一点,但我无法到这一点,因为我无法获取用于存储信息的数组
路径没有问题
答案 0 :(得分:2)
会有错误出现,可以在控制台中看到。
innerhtml
必须为innerHTML
storeRandom
在功能上与strorerandom
相同的情况与stroreRandom
不同
//array
window.onload = myFunction();
function myFunction(){
var storeRandom= [];
for (var i = 0; i <= 25; i++){
var random = Math.floor((Math.random() * 78) + 1);
storeRandom.push(random);
x = document.getElementById("demo");
x.innerHTML= storeRandom;
}
}
<!DOCTYPE html>
<html>
<head>
<link rel= "stylesheet" type = "text/css" href ="css/mystyle.css">
</head>
<body>
<Table id = table>
<tr>
<td class = "bingocell">1</td>
<td class = "bingocell">2</td>
<td class = "bingocell">3</td>
<td class = "bingocell" id = 4>4</td>
<td class = "bingocell" id = 5>5</td>
</tr>
<tr>
<td class = "bingocell" id = 6>1</td>
<td class = "bingocell" id = 7>2</td>
<td class = "bingocell" id = 8>3</td>
<td class = "bingocell" id = 9>4</td>
<td class = "bingocell" id = 10>5</td>
</tr>
<tr>
<td class = "bingocell" id = 11>1</td>
<td class = "bingocell" id = 12>2</td>
<td class = "bingocell" id = 13>3</td>
<td class = "bingocell" id = 14>4</td>
<td class = "bingocell" id = 15>5</td>
</tr>
<tr>
<td class = "bingocell" id = 16>1</td>
<td class = "bingocell" id = 17>2</td>
<td class = "bingocell" id = 18>3</td>
<td class = "bingocell" id = 19>4</td>
<td class = "bingocell" id = 20>5</td>
</tr>
<tr>
<td class = "bingocell" id = 21>1</td>
<td class = "bingocell" id = 22>2</td>
<td class = "bingocell" id = 23>3</td>
<td class = "bingocell" id = 24>4</td>
<td class = "bingocell" id = 25>5</td>
</tr>
</Table>
<p>Click the button to display a random number between 1 and 78.</p>
<button id = "button" onclick = "myFunction()">Try it</button>
<p id="demo"></p>
<!--
<script>
function myFunction() {
var x = document.getElementById("demo")
x.innerHTML = Math.floor((Math.random() * 78) + 1);
}</script>
-->
<script src = "js/script.js"></script>
</body>
</html>
答案 1 :(得分:0)
javascript的变量区分大小写。 strorerandom!= stroreRandom