有了這個HTML表:使得隨機彩色數字
<html>
<head>
<meta charset="UTF-8">
<title>Bonoloto</title>
<script src="bonoloto.js"></script>
<style>
table {border-collapse: collapse;}
td{border: 1px solid #000000; text-align: center; width: 6%;}
</style>
</head>
<body>
<script>
tables();
</script>
</body>
</html>
而且此javascript:
var counter = 0;
var nr1 = Math.floor(Math.random() * 49 + 1),
nr2 = Math.floor(Math.random() * 49 + 1),
nr3 = Math.floor(Math.random() * 49 + 1),
nr4 = Math.floor(Math.random() * 49 + 1),
nr5 = Math.floor(Math.random() * 49 + 1);
document.write("Numbers: "+nr1+" "+nr2+" "+nr3+" "+nr4+" "+nr5);
function tables(){
document.write("<table>");
for(i = 1; i < 50; i++) {
if(counter == 10) {
counter = 0;
document.write("<tr>");
}
if(i==nr1){
document.write("<td style='background-color: cadetblue'>" + i + "</td>");
}else{
document.write("<td>" + i + "</td>");
}
if(counter == 10) {
counter = 0;
document.write("</tr>");
}
counter++;
}
document.write("</table>");
}
這是輸出:
我必須強調所有喜歡的數字25突出顯示。數字是隨機產生的,目的是在表格中突出顯示它們。我被卡在這裏:
if(i==nr1){
document.write("<td style='background-color: cadetblue'>" + i + "</td>");
}else{
document.write("<td>" + i + "</td>");
}
如果我放置更多的if語句表列將「乘」。我不能讓這種情況正常工作...