我做HTML中的按鈕,我想它來調用函數在javascript:HTML,Java腳本:按鈕不調用函數
的index.html
<body onLoad="setGameAreaBounds()" onResize="setGameAreaBounds()">
<div id="scoreLabel">Score: 0 </div>
<!--div Group-->
<div>
<p id="pageTitle">Button Chaser</p>
<input type="button" id="startButton" onClick="start()" value="Start"/>
</div>
<!--The following: gameArea and dot is grouped together-->
<div id="gameArea">
<button id="dot" onClick="detectHit()"></button>
</div>
</body>
buttonChaser.js
function detectHit() {
//Increase the var score
}
function setGameAreaBounds() {
//Setting the size of GameBoard/Window
}
function moveDot() {
//randomly move the button(id: dot) within the GameBoard/window
}
function start() {
alert("sometext");
moveDot();
}
的代碼運行正常,如果我把moveDot();
函數內部setGameAreaBounds();
然而,這似乎是按鈕(ID:startButton)從未連接的功能start();
我做了什麼錯?
請張貼控制檯錯誤。 –
我使用的是Firefox>開發人員> Web控制檯。當我點擊開始,它說:'TypeError:開始不是一個函數'然後在它下面:'onClick()index.html:1'它是否足夠的信息? – user2789240