3
有了這個代碼:jQuery獲取上下文嗎?
$(".toggle", '.Div1').on('click',function()
{
alert("I was clicked becuase im .toggle is under the context of _________");
});
我需要得到該$(this)
值下的上下文。
如何獲得_______
的值?
有了這個代碼:jQuery獲取上下文嗎?
$(".toggle", '.Div1').on('click',function()
{
alert("I was clicked becuase im .toggle is under the context of _________");
});
我需要得到該$(this)
值下的上下文。
如何獲得_______
的值?
這是不可能的。 Event對象不包含任何對用於綁定它的jQuery對象的引用。
我認爲'context()'會爲你做這件事,但它似乎是所選元素的上下文:http://jsfiddle.net/RoryMcCrossan/mHszf/ –
另外,爲什麼你需要這個?如果你指定一個上下文,那麼你必須已經知道它是什麼? –
'$(「#toggle」,'#Div1')'沒有任何意義。 '$(「#Div1 #toggle」)會有一定的意義,但是真的,'$('#toggle')'應該完成這項工作,除非該元素可以位於DOM樹的不同位置。 – ThiefMaster