內選擇考慮以下幾點: -jQuery的 - 點擊方法
$("#id").click(function(){
// how do i access $("#id") here: say i want to add a class to #id? without $("#id")
});
內選擇考慮以下幾點: -jQuery的 - 點擊方法
$("#id").click(function(){
// how do i access $("#id") here: say i want to add a class to #id? without $("#id")
});
可以使用this
上下文來訪問選擇的項目。
$("#id").click(function() {
$(this).addClass("blah");
});
另外,每個事件處理程序也將傳遞一個事件,你可以得到你從的信息:
$("#id").click(function(evt) {
$(evt.target).addClass("blah");
});
但是,我通常贊成使用this
的方法。
$(this).addClass("class");
閱讀JQuery documentation,你會發現,你應該使用$(this)
。
Bah。到10秒。 :p – nlaq 2009-11-13 09:26:03