我正在嘗試使用ajax製作一個按鈕,該按鈕最喜歡該線程。但它只能淡入淡出喜歡的線索上的收藏圖片。在jQuery中使用'this'變量fadeIn?
我收到以下錯誤: Uncaught SyntaxError: Unexpected token this
這是我的代碼行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
,使它只褪色點擊一個。
這仍然給出相同的錯誤。我真的不知道爲什麼,我之前使用過這種方法,但不是'$ .post'。 –
沒關係,我知道了,另一個問題是,'function(...)'應該改成'function(){...}' –
非常感謝.... –