0

以下の jQuery ゲームは、間隔 3000 にバインドされた aspx で作成されています。

$(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 を移動します。ただし、エントリと合計変数が等しいかどうかを確認してから車を += 25 px 右に動かす代わりに、3000 ミリ秒ごとに新しいランダム変数を指定するインパルスを取得します。なぜこうなった?

4

1 に答える 1

1

ボタントリガーが実際に等価チェックの一部になることを意味していると思うので、括弧が必要です:

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
}
于 2013-09-16T17:21:13.540 に答える