<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>贪吃蛇</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="ssq.js"></script> <style type="text/css"> .container { text-align: center; margin: 20px auto; } .nums { text-align: center; margin: 10px auto; padding: 0px; width: 200px; } .nums table { width: 100%; height: 100%; } .nums table td { border: 1px solid black; font-size: 36px; } </style> <script type="text/javascript"> var speed = [1,2,3,4,5,6,7]; var intervalKey; function playSSQ() { setButtonName(); play(); } function play() { if(intervalKey) { clearInterval(intervalKey); intervalKey = undefined; } else { intervalKey = setInterval(letItGo, 1000); } } function letItGo() { //randomSpeed(); var tds = document.getElementsByTagName('td'); for(var i = 0; i < tds.length; i ++) { var v = parseInt(tds[i].innerHTML); tds[i].innerHTML = (v + speed[i]) % 9 + 1; } } function randomSpeed() { for(var i = 0; i < speed.length; i ++) { var v = Math.random() * 10; speed[i] = Math.floor(v); } } function setButtonName() { var b = document.getElementById("playButton"); if(b.innerHTML === '开始') { b.innerHTML = '停止'; } else { b.innerHTML = '开始'; } } </script> </head> <body> <div class="container"> <h1>大家一起玩双色球</h1> <div class="nums"> <table border="0" cellspacing="10" cellpadding="0"> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td> <td>7</td> </tr> </table> </div> <div> <button id="playButton" onclick="playSSQ();">开始</button> </div> </div> </body> </html>
。。。
你这是以前贪吃蛇控制速度的代码改的吧,我说看了半天怎么是speed呢,不过大致还是这样了,要修改修改