我有這樣的情況 -
$('<first-selector>').each(function(){
$(this).click(function(){
$('<second-selector>').click(function(){
/* Here I want to use the top $(this) reference to do some business.
I don't want to use like var thisObj = $(this) and refer it inside
the click function*/
});
});
});
如何使用另一個對象裏面$(this)
參考?
爲什麼你不想在輸入第二個回調之前保存'$(this)'? –
@ChristopherArmstrong這是我不想做的。我在評論中提到了相同的內容。 – Sriram
您已經確定了唯一的(明智的)解決方案。系統變量'this'會被自動替換以反映當前範圍,因此要從不同範圍內引用它,您必須手動將其緩存在其他變量中。 –