我在下面有这个 jQuery 游戏,它是用 aspx 制作的,它的间隔是 3000。
$(document).ready(function () {
var interval; //start timer
interval = setInterval(function () { //write timer function
var num1 = parseInt($("#Label1").html()); //number1 is my label1
var num2 = parseInt($("#Label3").html()); //number2 is my label3
var total = num1 + num2; //find total of these two
var entry = parseInt($("#TextBox1").val()); //the number your enter is entry
if (entry == total) //the timer will check every 100 ms if they match
$(".car").css("left", "+=25px"); //if they match, move the car 25 px to the right
$('#Button1').trigger('click'); //and trigger button1, so button1 throws new dice and car doesn't move further
}, 3000);
});
我希望间隔脉冲检查数字是否匹配并沿 x 轴移动 .car div。但是,我得到每 3000 毫秒指定一个新随机变量的冲动,而不是检查条目和总 var 是否相等,然后将 car += 25 px 向右移动。为什么会这样?