我有以下功能,但由于某种原因,它会触发两次。为什么会发生这种情况,如何修复它,因为此函数会增加全局计数器?
感谢您的所有帮助!
$("body").on("click", "#moveOn", function (e) {
var currentLocation = $(".backgroundImage.currentLocation");
$(currentLocation).removeClass("currentLocation").addClass("leaveLocation");
var nextLocationClass = $(this).attr("data-nextLocation");
var nextLocation = $(".backgroundImage." + nextLocationClass);
$(nextLocation).removeClass("hidden").addClass("moveToLocation");
console.log("Clicked arrow " + dataHolder.data.currLocation);
(dataHolder.data.currLocation)++;
$(this).addClass("hidden");
setTimeout(function () {
$(currentLocation).addClass("hidden").removeClass("leaveLocation");
$(nextLocation).addClass("currentLocation").removeClass("moveToLocation");
}, 6000);
e.stopPropagation();
});