gpt4 book ai didi

javascript - 在 JQuery bool 属性之间切换

转载 作者:行者123 更新时间:2023-11-27 23:10:01 26 4
gpt4 key购买 nike

我有一个事件监听器,我试图在类(正在运行)和 true/false 数据选择属性(未运行)之间切换。我已经将 div class="dice"的 data-selection 属性默认设置为 false。

game.selection = function() {
$(".dice").on("click", function() {
$(this).toggle(function () {
$(this).attr('data-selection', true);
});
$(this).toggleClass("active");
});
};

最佳答案

替换:

$(this).toggle(function () {
$(this).attr('data-selection', true);
});

作者:

$(this).attr('data-selection', ($(this).attr('data-selection') == "false" ? true : false));

关于javascript - 在 JQuery bool 属性之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36274393/

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