找出$(this)
目前在jQuery中等效的最佳方式是什麼?
例如沒有太大的幫助。
我問的原因是一段代碼目前沒有做它應該做的事情,我已經將代碼移到一個函數中。
下面的摘錄現在在一個函數中,而$(this)現在似乎指的是DOMWindow。
if($(this).hasClass('open'))
{
alert('I should be closed');
$(this).removeClass('open').addClass('closed');
$(this).parents('article').css('border', '1px solid red').animate({'width': '212px'}, 100, "linear", function() {
run_masonry();
});
}
else
{
alert('I should be open');
$(this).removeClass('closed').addClass('open');
$(this).parents('article').css('border', '1px solid blue').animate({'width': '646px'}, 100, "linear", function() {
run_masonry();
});
}
我該如何保持$(this)是原始點擊元素?
反正是有縮小它返回大量的數據 – 2012-01-06 10:33:39
@CraigWard,是的,使用'的console.log(本);'只次登錄? e本地對象而不是'$(this)'。 – 2012-01-06 10:34:49
@CraigWard你想把它縮小到什麼程度?我希望它是'$(this).attributesThatIWantToSee()' – Connell 2012-01-06 10:36:43