我有以下功能,但由于某种原因,它会触发两次。为什么会发生这种情况,我该如何解决,因为这个函数会增加一个全局计数器?
感谢您所有的帮助!
$("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();
});