我正在尝试制作一个开始按钮,但是每当我测试该程序时,它都会显示但没有执行任何操作。
这就是我所拥有的:
var startGame = function() { //when the start button is clicked, the game starts
$('#startButton').click(function() {
$('#main').hide();
playing = true;
});
}
$(document).ready(startGame()); //when the html loads, start the function
while (playing) {
//this is the main loop for the program
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body id="textHere">
<div id="main">
<h1>I am a computer.</h1>
<a class="button" id="startButton">START</a>
<!--this is the button-->
</div>
<script src="" https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js ""></script>
</script>
<script src='I%20am%20a%20computer.js'></script> <!--where it gets the script-->
</body>
您正在调用
startGame
函数,而不是将其传递给 document.ready
。应该是:
$(document).ready(startGame);
当您在函数名称后面加上括号时,它会立即调用它。要将函数用作值,请省略括号。
不只是没有 lopEMic0e9i uefr oeiofem0io;wmepowqo[ w