照着书上码的,为啥点click会奔溃?

来源:9-22 编程练习

gogoyear

2016-09-25 17:11

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Make My Own Bingo</title>
    <link href="card.css" rel="stylesheet" type="text/css">
    <script src="nun.js"></script>
</head>
<body>
<h1>Create A Bingo Card</h1>
<table>
    <tr>
        <th>B</th>
        <th>I</th>
        <th>N</th>
        <th>G</th>
        <th>O</th>
    </tr>
    <tr>
        <td id="square0">&nbsp;</td>
        <td id="square5">&nbsp;</td>
        <td id="square10">&nbsp;</td>
        <td id="square14">&nbsp;</td>
        <td id="square19">&nbsp;</td>
    </tr>
    <tr>
        <td id="square1">&nbsp;</td>
        <td id="square6">&nbsp;</td>
        <td id="square11">&nbsp;</td>
        <td id="square15">&nbsp;</td>
        <td id="square20">&nbsp;</td>
    </tr>
    <tr>
        <td id="square2">&nbsp;</td>
        <td id="square7">&nbsp;</td>
        <td id="free">Free</td>
        <td id="square16">&nbsp;</td>
        <td id="square21">&nbsp;</td>
    </tr>
    <tr>
        <td id="square3">&nbsp;</td>
        <td id="square8">&nbsp;</td>
        <td id="square12">&nbsp;</td>
        <td id="square17">&nbsp;</td>
        <td id="square22">&nbsp;</td>
    </tr>
    <tr>
        <td id="square4">&nbsp;</td>
        <td id="square9">&nbsp;</td>
        <td id="square13">&nbsp;</td>
        <td id="square18">&nbsp;</td>
        <td id="square23">&nbsp;</td>
    </tr>
</table>
<p><a href="index.html" id="reload">Click here</a> to create a new card</p>
</body>
</html>
window.onload=initAll;
var usedNum = new Array(76);
function initAll(){
    //-----------检查浏览器是否支持js
    if (document.getElementById){
        document.getElementById("reload").onclick = anotherCard;
        newCard();
    }
    else {
        alert("Sorry,your broeser doesn't support this script")
    }

}
function newCard(){
    for (var i=0;i<24;i++){
        setSquare(i);
    }
}

function setSquare(thisSquare){

    var currSquare = "square" + thisSquare;
    var colPlace = new Array(0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,3,3,4,4,4,4,4);
    var colBasis = colPlace[thisSquare] * 15;
    var newNum;
    do{
        newNum = colBasis + getNewNum() + 1;
    }
    while(usedNum[newNum]);

    usedNum[newNum]=true;
    document.getElementById(currSquare).innerHTML = newNum;
}

function getNewNum(){
    return Math.floor(Math.random() * 15);
}

function anotherCard(){
    for (var i=1;1<usedNum.length;i++){
        usedNum[i]=false;
    }
    newCard();
}


写回答 关注

1回答

  • 茹蜾
    2016-09-28 10:37:25
    已采纳

    --小伙子。这里是i不是1http://img.mukewang.com/57eb2cda0001c33e03000121.jpg死循环了

    gogoye...

    非常感谢!

    2016-10-16 16:33:14

    共 1 条回复 >

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468065 学习 · 21891 问题

查看课程

相似问题