gpt4 book ai didi

javascript - 在 jQuery 中使用 .fadeOut() 时禁用单击

转载 作者:行者123 更新时间:2023-12-02 19:09:43 26 4
gpt4 key购买 nike

我正在制作一款纸牌游戏。当用户单击该卡片时,该卡片就会淡出。然而,目前存在一个严重的错误。用户可以多次单击一张卡,将多个卡号添加到一个数组中(本质上是选择很多卡)。

我该如何解决这个问题?这是到目前为止我的代码:

$(clicked_id).fadeOut('fast');

如有任何帮助,我们将不胜感激!

编辑:整个代码:

<script>
var cardsPicked = new Array;

var suits = ["&hearts;", "&diams;", "&clubs;", "&spades;"];
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 调用的:

$(clicked_id).prop("onclick", "").off().fadeOut('fast');

DEMO

关于javascript - 在 jQuery 中使用 .fadeOut() 时禁用单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13896522/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com