2012-11-21 43 views

回答

0

您仍然可以通过$(this)访问它,就像在.click中一样。

Demo

0

你可以用$(this)访问它的处理器

$('body').on('click','.class', function() { 
    $(this) or this // This points to the element with .class 
      // which you just clicked 
    alert($(this).attr('class')); // Gets the class name 
}); 
+0

的$(这)会选择body标签,不符合的.class标签的元素。 – user1841175

+0

nope ..它将选择.class,因为它已被委托给主体 –

+0

$('body')。on('click',function(){将选择body,但是$('body')。on ('click','。class',function(){将选择嵌套在body中的.class –

1

您可以使用this获取JavaScript对象或$(this)得到jQuery对象内。

$('body').on('click','.class', function() { 
    alert(this.id); //with this, javascript provided properties or methods. 
    alert($(this).attr('id')); // with $(this) jquery provided properties or methods. 
}); 
0

试试这个:

$('body').on('click','.class', function() { 
    $(this).<some property here>; 
});