JavaScript版打倉鼠V1

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
    function check(td) {
        //alert(td.innerHTML);

        var c = td.innerHTML;
        var scoreT = document.getElementById("score").innerHTML;
        var score = parseInt(scoreT);

        if (td.style.background == "red") {
            document.getElementById("score").innerHTML = score + 1;
            td.style.background = "";
        }

        //alert(score+parseInt(c)+Math.floor(Math.random()*9));
        ;
    }
    var curTd = null;
    setInterval(function() {
        if (curTd != null)
            curTd.style.background = "";
        var num = Math.floor(Math.random() * 9) + 1;
        var idNum = "td" + num;
        //alert(idNum);
        document.getElementById(idNum).style.background = "red";
        curTd = document.getElementById(idNum);
    }, 2000);

    function calc(td) {

    }
</script>
</head>
<body>
    <div id="score">0</div>
    <table style="width: 50%; height: 300px;" border="1">
        <tr>
            <td id="td1" οnclick="check(this)">1</td>
            <td id="td2" οnclick="check(this)">2</td>
            <td id="td3" οnclick="check(this)">3</td>
            
        </tr>
        <tr>
            <td id="td4" οnclick="check(this)">4</td>
            <td id="td5" οnclick="check(this)">5</td>
            <td id="td6" οnclick="check(this)">6</td>
        </tr>
        <tr>
            <td id="td7" οnclick="check(this)" >7</td>
            <td id="td8" οnclick="check(this)">8</td>
            <td id="td9" οnclick="check(this)">9</td>

        </tr>
    </table>
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章