使用on()时如何引用$(this)

时间:2013-01-10 05:48:06

标签: this jquery jquery-on

我正在使用on()来模仿live(),并且在我的生活中无法弄清楚如何正确引用$(this)以便它引用我传入的选择器。这是代码,$(this)返回"body"而不是"select"

$("body").on("change", "select", function(e){
    console.log($(this));
});

2 个答案:

答案 0 :(得分:2)

试试这个

$(e.currentTarget);

e实际上是事件的事件参数,这就是你想要的信息。

答案 1 :(得分:1)

您可以将event.target用于事件来源。

<强> Live Demo

$("body").on("change", "select", function(e){
    console.log($(e.target));
});