[英]Why doesn't my mouseOver functions work?
游戏非常简单,您可以单击开始按钮开始,然后沿着轨道移动鼠标直到到达终点,然后计时器停止并显示得分。 如果您走出赛道,您将得到零分。
为什么我的mouseOver函数不起作用? 链接到我的完整代码: http : //www.codecademy.com/TictacTactic/codebits/AQBK4L/edit
先感谢您!
var score = 1000;
var timer = setInterval(countDown(), 1000);
$(document).ready(function() {
$('#start').click(function() {
$('#game').mouseover(function() {
stopTimer();
score = 0
$('#points').html(score)
});
$('#end').mouseover(function() {
stopTimer()
$('#points').html(score)
});
});
});
function countDown() {
score = score - 1;
}
function stopTimer() {
clearInterval(timer);
}
大多数事件都是小写的,例如mouseover
, mouseout
等。还有其他一些大写的东西,例如DOMContentLoaded
。 大多数(如果不是全部)编程语言都区分大小写,请当心。
尝试这个
var clicked = false;
$('#start').click(function() {
if(!clicked){
clicked = true;
}
});
$("#game").hover(function(){
if(clicked){
stopTimer();
score = 0;
$("#points").html(score);
}
});
$("#end").hover(function(){
if(clicked){
stopTimer();
$("#points").html(score);
}
});
然后,如果您不希望悬停事件起作用,只需将clicked设置为false IE:clicked = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.