本文介绍了在jQuery中使用.fadeOut()时禁用点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作纸牌游戏.当用户单击卡时,卡淡出.但是,此刻存在一个严重的错误.用户可以多次单击一张卡,从而将多个卡号添加到阵列中(实际上是挑选很多卡).
I am building a card game. When the user clicks the card, the card fades out. However, at the moment, there is a serious bug. The user can click one card multiple times, adding multiple card numbers to an array (essentially picking lots of cards).
我该如何解决?到目前为止,这是我的代码:
How can i resolve this? Here is my code so far:
$(clicked_id).fadeOut('fast');
任何帮助将不胜感激!
完整代码:
<script>
var cardsPicked = new Array;
var suits = ["♥", "♦", "♣", "♠"];
var king = 0;
var numbers = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
var cardRules = ["Waterfall", "You", "Me", "Girls", "Thumbmaster", "Guys", "Heaven", "Mate", "Rhyme", "Catagories", "Make a rule", "Question master", "Pour your drink!"];
var currentId;
function getCard(clicked_id) {
clicked_id = "#" + clicked_id;
$(clicked_id).fadeOut('fast');
var newCard = Math.floor((Math.random() * 13) + 1);
var newSuit = Math.floor((Math.random() * 4) + 1);
var currentCard;
var x = document.getElementById("pick");
var rules = document.getElementById("rules");
var kings = document.getElementById("kings");
var currentCards = document.getElementById("currentCard");
if (cardsPicked.indexOf(numbers[newCard - 1] + " " + suits[newSuit - 1]) == -1) {
if (numbers[newCard - 1] == "K" && king < 4) {
king = king + 1;
}
if (king == 4) {
king = "All kings found!";
alert("Fourth king picked. Down the jug!");
}
cardsPicked.push(numbers[newCard - 1] + " " + suits[newSuit - 1]);
for (count = 0; count < cardsPicked.length; count++)
currentRule = cardRules[newCard - 1];
x.innerHTML = cardsPicked;
currentCards.innerHTML = numbers[newCard - 1] + " " + suits[newSuit - 1];
rules.innerHTML = currentRule;
kings.innerHTML = king;
} else {
getCard();
}
}
推荐答案
尝试一下
$(clicked_id).off().fadeOut('fast');
如果事件是由内联onclick
调用的:
In case the event is called by inline onclick
:
$(clicked_id).prop("onclick", "").off().fadeOut('fast');
这篇关于在jQuery中使用.fadeOut()时禁用点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!