gpt4 book ai didi

javascript - 单击操作不会绑定(bind)

转载 作者:行者123 更新时间:2023-11-28 00:04:25 25 4
gpt4 key购买 nike

下面的代码仅在我注释掉点击代码时才有效 - 也就是说,如果我不注释掉点击事件处理程序,悬停功能甚至无法工作,所以我知道这是罪魁祸首。知道出了什么问题吗?

非常感谢!

 $(document).ready(function() {

/* helper function to main database querying function
below. Figures out the number of activities needed
for completeness. Takes the box's class name as an
argument
*/
var complete = function(arg) {
switch(arg) {
case "three":
return 3;
case "four":
return 4;
case "seven":
return 7;
}
};


// determine if we change color of box
var changeColor = function(arg) {
if (arg.hasClass("zero")) {
arg.removeClass("zero").addClass("between");
}
else if (arg.hasClass("between")) {
if (numComplete == toComplete) {
arg.removeClass("between").addClass("complete");
}
}
};


// CHANGE BOX COLOR WHEN HOVERING OVER IT
$(".innerBox").hover(function() {
if ($(this).hasClass("zero")) {
$(this).addClass("innerBoxHoverGrey");
}
else if ($(this).hasClass("between")) {
$(this).addClass("innerBoxHoverYellow");
} else {
$(this).addClass("innerBoxHoverGreen");
}},

function() {
if ($(this).hasClass("innerBoxHoverGrey")) {
$(this).removeClass("innerBoxHoverGrey");
} else if ($(this).hasClass("innerBoxHoverYellow")) {
$(this).removeClass("innerBoxHoverYellow");
} else {
$(this).removeClass("innerBoxHoverGreen");
}
}
);


// WHERE ALL THE JUICE IS - CLICK ON A BOX, CHECK WITH DATABASE
$(".innerBox").bind("click", function() {

// This is what we'll be passing to everything
var className = $(this).attr("id");
var numComplete;
var toComplete;

// DATA TO PASS
var data = {
"val": className
};

// TAKE CARE OF TIME FIRST
var recentlyCompleted = false;


$.getJSON("time.php", function(result) {
$.each(result, function(key, val)) {
recentlyCompleted = val;
};
});

/*
if (!recentlyCompleted) {
throw new Error("error");
} else {

// UPDATE ACTIVITY TABLE - not meant to return anything
$.getJSON("updateActivityTable.php", data, function(newResult) {
alert(newResult);
});

// UPDATE TIME TABLE - not meant to return anything
$.getJSON("updateActivityTimeTable.php", data, function(newResult) {
alert(newResult);
});

// UPDATE UI BASED ON ACTIVITIES COMPLETED
var spanName = className + "Num";

$.getJSON("getActivityNum.php", data, function(newResult) {
$.each(result, function(key, val)) {
$("#"+spanName).html(val);
numComplete = val;
}});


// figure out how many activities means its
// complete
toComplete = complete($(this).attr("class"));

changeColor($(this));
}*/
});

})

最佳答案

键单击事件的每个循环中都有语法错误。错误在这里: $.each(result, function (key, val)) { 它应该是,

$.getJSON("time.php", function(result) {
$.each(result, function(key, val) {
recentlyCompleted = val;
});
});

关于javascript - 单击操作不会绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31494194/

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