SORU
20 ŞUBAT 2013, ÇARŞAMBA


jQuery tıklama ateş birden çok kez olaylar

Bunun temelleri aşağı almak için bir yol olarak Javascript ile video poker oyunu yazma girişiminde bulunuyorum ve jQuery tıklayın işleyicileri ateş birden çok kez olay nerede bir sorun haline koşuyoruz.

Onlar ekli düğmeleri yerleştirmek için bir bahis ve ince işleri için yerleştirme bahis ilk el sırasında bir oyun (ateş yalnızca bir kez); ama bahis için ikinci el, yangınlar click olayı iki kez, her zaman bir bahis veya bahis düğmesini basılı tutun (yani iki kez doğru miktarda bahis için her basın). Genel olarak, click olayı bahis bir düğme nerede ... bir kere basıldığında tetiklenir sayısı için bu izlergel ..dizinin terim bu bahis içingel ..el başında oyun: 1, 2, 4, 7, 11, 16, 22, 29, 37, 46, hangi taksicinin n(n 1)/2 1 için ne olursa olsun bunun değerini ben değildim, yeterince akıllı olduğunu düşünüp, kullandım OEIS. :)

Burada yukarı hareket edilir tıklatın olay işleyicileri ile işlevi; umarım kolay anlamak için (eğer değilse, bu işte daha iyi olsun istiyorum beni de haberdar):

/** The following function keeps track of bet buttons that are pressed, until place button is pressed to place bet. **/
function pushingBetButtons() {
    $("#money").text("Money left: $"   player.money); // displays money player has left

    $(".bet").click(function() {
        var amount = 0; // holds the amount of money the player bet on this click
        if($(this).attr("id") == "bet1") { // the player just bet $1
            amount = 1;
        } else if($(this).attr("id") == "bet5") { // etc.
            amount = 5;
        } else if($(this).attr("id") == "bet25") {
            amount = 25;
        } else if($(this).attr("id") == "bet100") {
            amount = 100;
        } else if($(this).attr("id") == "bet500") {
            amount = 500;
        } else if($(this).attr("id") == "bet1000") {
            amount = 1000;
        }
        if(player.money >= amount) { // check whether the player has this much to bet
            player.bet  = amount; // add what was just bet by clicking that button to the total bet on this hand
            player.money -= amount; // and, of course, subtract it from player's current pot
            $("#money").text("Money left: $"   player.money); // then redisplay what the player has left
        } else {
            alert("You don't have $"   amount   " to bet.");
        }
    });

    $("#place").click(function() {
        if(player.bet == 0) { // player didn't bet anything on this hand
            alert("Please place a bet first.");
        } else {
            $("#card_para").css("display", "block"); // now show the cards
            $(".card").bind("click", cardClicked); // and set up the event handler for the cards
            $("#bet_buttons_para").css("display", "none"); // hide the bet buttons and place bet button
            $("#redraw").css("display", "block"); // and reshow the button for redrawing the hand
            player.bet = 0; // reset the bet for betting on the next hand
            drawNewHand(); // draw the cards
        }
    });
}

Lütfen bana bildirin varsa herhangi bir fikir veya öneri veya çözüm için benim sorunum benzer bir çözüm için bir başka sorun burada (baktım çok benzer başlıklı konuları ve hiç şans bulmak bir çözüm olabilir benim için).

CEVAP
2 Ocak 2014, PERŞEMBE


.unbind() önerilmiyor ve .off() yöntemi kullanmalısınız. Sadece .on() aramadan önce .off() Ara.

Bu tüm olay işleyicileri kaldırır:

$(element).off().on('click', function() {
    // function body
});

Sadece kayıtlı '' olay işleyicileri: . kaldırmak için

$(element).off('click').on('click', function() {
    // function body
});

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Dylan Brenan

    Dylan Brenan

    22 Aralık 2009
  • PhoneArena

    PhoneArena

    7 NİSAN 2006
  • THELIFEOFPRICE

    THELIFEOFPRI

    16 Mart 2011