gpt4 book ai didi

javascript - 在 jQuery 淡入中使用 'this' 变量?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:57:20 26 4
gpt4 key购买 nike

我正在尝试使用 ajax 制作一个按钮,该按钮将收藏线程。但它必须只淡入和淡出收藏线程上的收藏图像。

我收到以下错误:未捕获的语法错误:意外的 token

那是我的代码第 11 行:$(this + '.is_favorited').fadeIn("slow");

这是完整的 Javascript 源代码:

$(".do_favorite").live("click", function() {
var item = $(this).closest(".box");
var content = $(this).attr('data-id');
alert(content);
$.post( 'ajax.favorite.php?sid=' + content + '',
$(this).serialize(),
function(data) {
if (data == "1") {
// Favorite it
$(this + ' .not_favorited').fadeOut("slow", function (
$(this + ' .is_favorited').fadeIn("slow");
));
}else if (data == "2") {
// Un-Favorite it
$(this + ' .is_favorited').fadeOut("slow", function (
$(this + ' .not_favorited').fadeIn("slow");
));
}else {
alert("DER SKETE EN FEJL DU");
}
}
);
return false;
});

希望有人能帮我解决这个问题,因为我真的需要使用this,让它只在点击的时候淡出。

最佳答案

你可以这样写:

$(this).find('.not_favorited')

关于javascript - 在 jQuery 淡入中使用 'this' 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14211737/

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